try_parse_monotonic_iso8601_timestamp.slt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. mode cockroach
  10. # Real-world example
  11. query T
  12. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56:04.123Z');
  13. ----
  14. 2015-09-18 23:56:04.123
  15. # Minimum accepted timestamp
  16. query T
  17. select try_parse_monotonic_iso8601_timestamp('0000-01-01T00:00:00.000Z');
  18. ----
  19. 0001-01-01 00:00:00 BC
  20. # Minimum AD timestamp
  21. query T
  22. select try_parse_monotonic_iso8601_timestamp('0001-01-01T00:00:00.000Z');
  23. ----
  24. 0001-01-01 00:00:00
  25. # Maximum accepted timestamp
  26. query T
  27. select try_parse_monotonic_iso8601_timestamp('9999-12-31T23:59:59.999Z');
  28. ----
  29. 9999-12-31 23:59:59.999
  30. # NULL
  31. query T
  32. select try_parse_monotonic_iso8601_timestamp(NULL);
  33. ----
  34. NULL
  35. # Negative timestamp
  36. query T
  37. select try_parse_monotonic_iso8601_timestamp('-2015-09-18T23:56:04.123Z');
  38. ----
  39. NULL
  40. # Missing microseconds
  41. query T
  42. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56:04Z');
  43. ----
  44. NULL
  45. # Wrong timezone
  46. query T
  47. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56:04.123-05');
  48. ----
  49. NULL
  50. # Extra stuff on the end
  51. query T
  52. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56:04.123Znope');
  53. ----
  54. NULL
  55. # Alternate ISO8601 format (missing separators)
  56. query T
  57. select try_parse_monotonic_iso8601_timestamp('20150918T235604.123Z');
  58. ----
  59. NULL
  60. # Leading whitespace
  61. query T
  62. select try_parse_monotonic_iso8601_timestamp(' 2015-09-18T23:56:04.123Z');
  63. ----
  64. NULL
  65. # Trailing whitespace
  66. query T
  67. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56:04.123Z ');
  68. ----
  69. NULL
  70. # Not a timestamp
  71. query T
  72. select try_parse_monotonic_iso8601_timestamp('nope');
  73. ----
  74. NULL
  75. # Year: not enough digits
  76. query T
  77. select try_parse_monotonic_iso8601_timestamp('215-09-18T23:56:04.123Z');
  78. ----
  79. NULL
  80. # Year: too many digits
  81. query T
  82. select try_parse_monotonic_iso8601_timestamp('20015-09-18T23:56:04.123Z');
  83. ----
  84. NULL
  85. # Month: not enough digits
  86. query T
  87. select try_parse_monotonic_iso8601_timestamp('2015-9-18T23:56:04.123Z');
  88. ----
  89. NULL
  90. # Month: too small
  91. query T
  92. select try_parse_monotonic_iso8601_timestamp('2015-00-18T23:56:04.123Z');
  93. ----
  94. NULL
  95. # Month: too big
  96. query T
  97. select try_parse_monotonic_iso8601_timestamp('2015-13-18T23:56:04.123Z');
  98. ----
  99. NULL
  100. # Days: not enough digits
  101. query T
  102. select try_parse_monotonic_iso8601_timestamp('2015-09-8T23:56:04.123Z');
  103. ----
  104. NULL
  105. # Days: too small
  106. query T
  107. select try_parse_monotonic_iso8601_timestamp('2015-09-00T23:56:04.123Z');
  108. ----
  109. NULL
  110. # Days: too big (sept has 30 days)
  111. query T
  112. select try_parse_monotonic_iso8601_timestamp('2015-09-31T23:56:04.123Z');
  113. ----
  114. NULL
  115. # Hours: not enough digits
  116. query T
  117. select try_parse_monotonic_iso8601_timestamp('2015-09-18T4:56:04.123Z');
  118. ----
  119. NULL
  120. # Hours: too big
  121. query T
  122. select try_parse_monotonic_iso8601_timestamp('2015-09-18T24:56:04.123Z');
  123. ----
  124. NULL
  125. # Hours: alternate midnight
  126. query T
  127. select try_parse_monotonic_iso8601_timestamp('2015-09-18T24:00:00.000Z');
  128. ----
  129. NULL
  130. # Minutes: not enough digits
  131. query T
  132. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:6:04.123Z');
  133. ----
  134. NULL
  135. # Minutes: too big
  136. query T
  137. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:60:04.123Z');
  138. ----
  139. NULL
  140. # Seconds: not enough digits
  141. query T
  142. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56:4.123Z');
  143. ----
  144. NULL
  145. # Seconds: too big
  146. query T
  147. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56:60.123Z');
  148. ----
  149. NULL
  150. # Microseconds: not enough digits
  151. query T
  152. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56:04.12Z');
  153. ----
  154. NULL
  155. # Microseconds: too many digits
  156. query T
  157. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56:04.1234Z');
  158. ----
  159. NULL
  160. # Dash 0: wrong separator
  161. query T
  162. select try_parse_monotonic_iso8601_timestamp('2015_09-18T23:56:04.123Z');
  163. ----
  164. NULL
  165. # Dash 1: wrong separator
  166. query T
  167. select try_parse_monotonic_iso8601_timestamp('2015-09_18T23:56:04.123Z');
  168. ----
  169. NULL
  170. # T: wrong separator (lower case)
  171. query T
  172. select try_parse_monotonic_iso8601_timestamp('2015-09-18t23:56:04.123Z');
  173. ----
  174. NULL
  175. # Colon 0: wrong separator
  176. query T
  177. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23-56:04.123Z');
  178. ----
  179. NULL
  180. # Colon 1: wrong separator
  181. query T
  182. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56-04.123Z');
  183. ----
  184. NULL
  185. # Dot: wrong separator
  186. query T
  187. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56:04:123Z');
  188. ----
  189. NULL
  190. # Z: wrong timezone (lower case)
  191. query T
  192. select try_parse_monotonic_iso8601_timestamp('2015-09-18T23:56:04.123z');
  193. ----
  194. NULL
  195. # Regression test for a bug caught during code review of the PR adding this
  196. # func. We insert 3 things in a single persist batch where the least and
  197. # greatest values are valid, but the middle one isn't (so it gets mapped to
  198. # null). The bug was that the interpret would incorrectly conclude that none of
  199. # the values in the batch could be NULL.
  200. statement ok
  201. CREATE TABLE events (ts text);
  202. statement ok
  203. INSERT INTO events VALUES ('2015-09-18T23:56:04.123Z'), ('2015-09-18T23:56:04.124Znope'), ('2015-09-18T23:56:04.125Z');
  204. query T
  205. SELECT ts FROM events WHERE try_parse_monotonic_iso8601_timestamp(ts) IS NULL;
  206. ----
  207. 2015-09-18T23:56:04.124Znope