time.slt 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. # Copyright 2015 - 2019 The Cockroach Authors. All rights reserved.
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # This file is derived from the logic test suite in CockroachDB. The
  12. # original file was retrieved on June 10, 2019 from:
  13. #
  14. # https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/time
  15. #
  16. # The original source code is subject to the terms of the Apache
  17. # 2.0 license, a copy of which can be found in the LICENSE file at the
  18. # root of this repository.
  19. mode cockroach
  20. simple conn=mz_system,user=mz_system
  21. ALTER SYSTEM SET unsafe_enable_table_keys = true
  22. ----
  23. COMPLETE 0
  24. # Note that the odd '0000-01-01 hh:mi:ss +0000 UTC' result format is an
  25. # artifact of how pq displays TIMEs.
  26. query T
  27. SELECT '12:00:00':::TIME;
  28. ----
  29. 0000-01-01 12:00:00 +0000 UTC
  30. query T
  31. SELECT '12:00:00.456':::TIME;
  32. ----
  33. 0000-01-01 12:00:00.456 +0000 UTC
  34. query T
  35. SELECT '00:00:00':::TIME;
  36. ----
  37. 0000-01-01 00:00:00 +0000 UTC
  38. query T
  39. SELECT '23:59:59.999999':::TIME;
  40. ----
  41. 0000-01-01 23:59:59.999999 +0000 UTC
  42. query T
  43. select ('24:00'::TIME)::STRING
  44. ----
  45. 24:00:00
  46. query T
  47. SELECT ('24:00:00'::TIME)::STRING
  48. ----
  49. 24:00:00
  50. statement error could not parse
  51. SELECT '124:00'::TIME;
  52. statement error could not parse
  53. SELECT '24:00:01'::TIME;
  54. statement error could not parse
  55. SELECT '24:00:00.001'::TIME;
  56. # Timezone should be ignored.
  57. query T
  58. SELECT '12:00:00-08:00':::TIME;
  59. ----
  60. 0000-01-01 12:00:00 +0000 UTC
  61. query T
  62. SELECT TIME '12:00:00';
  63. ----
  64. 0000-01-01 12:00:00 +0000 UTC
  65. # Casting
  66. query T
  67. SELECT '12:00:00'::TIME;
  68. ----
  69. 0000-01-01 12:00:00 +0000 UTC
  70. query T
  71. select '12:00:00':::STRING::TIME;
  72. ----
  73. 0000-01-01 12:00:00 +0000 UTC
  74. query T
  75. SELECT '12:00:00' COLLATE de::TIME;
  76. ----
  77. 0000-01-01 12:00:00 +0000 UTC
  78. query T
  79. SELECT '2017-01-01 12:00:00':::TIMESTAMP::TIME;
  80. ----
  81. 0000-01-01 12:00:00 +0000 UTC
  82. query T
  83. SELECT '2017-01-01 12:00:00-05':::TIMESTAMPTZ::TIME;
  84. ----
  85. 0000-01-01 12:00:00 +0000 UTC
  86. query T
  87. SELECT '12h':::INTERVAL::TIME;
  88. ----
  89. 0000-01-01 12:00:00 +0000 UTC
  90. query T
  91. SELECT '12:00:00':::TIME::INTERVAL;
  92. ----
  93. 12:00:00
  94. query T
  95. SELECT '12:00:00':::TIME::STRING;
  96. ----
  97. 12:00:00
  98. # Comparison
  99. query B
  100. SELECT '12:00:00':::TIME = '12:00:00':::TIME
  101. ----
  102. true
  103. query B
  104. SELECT '12:00:00':::TIME = '12:00:00.000000':::TIME
  105. ----
  106. true
  107. query B
  108. SELECT '12:00:00':::TIME = '12:00:00.000001':::TIME
  109. ----
  110. false
  111. query B
  112. SELECT '12:00:00':::TIME < '12:00:00.000001':::TIME
  113. ----
  114. true
  115. query B
  116. SELECT '12:00:00':::TIME < '12:00:00':::TIME
  117. ----
  118. false
  119. query B
  120. SELECT '12:00:00':::TIME < '11:59:59.999999':::TIME
  121. ----
  122. false
  123. query B
  124. SELECT '12:00:00':::TIME > '11:59:59.999999':::TIME
  125. ----
  126. true
  127. query B
  128. SELECT '12:00:00':::TIME > '12:00:00':::TIME
  129. ----
  130. false
  131. query B
  132. SELECT '12:00:00':::TIME > '12:00:00.000001':::TIME
  133. ----
  134. false
  135. query B
  136. SELECT '12:00:00':::TIME <= '12:00:00':::TIME
  137. ----
  138. true
  139. query B
  140. SELECT '12:00:00':::TIME >= '12:00:00':::TIME
  141. ----
  142. true
  143. query B
  144. SELECT '12:00:00':::TIME IN ('12:00:00');
  145. ----
  146. true
  147. query B
  148. SELECT '12:00:00':::TIME IN ('00:00:00');
  149. ----
  150. false
  151. # Arithmetic
  152. query T
  153. SELECT '12:00:00':::TIME + '1s':::INTERVAL
  154. ----
  155. 0000-01-01 12:00:01 +0000 UTC
  156. query T
  157. SELECT '23:59:59':::TIME + '1s':::INTERVAL
  158. ----
  159. 0000-01-01 00:00:00 +0000 UTC
  160. query T
  161. SELECT '12:00:00':::TIME + '1d':::INTERVAL
  162. ----
  163. 0000-01-01 12:00:00 +0000 UTC
  164. query T
  165. SELECT '1s':::INTERVAL + '12:00:00':::TIME
  166. ----
  167. 0000-01-01 12:00:01 +0000 UTC
  168. query T
  169. SELECT '12:00:00':::TIME - '1s':::INTERVAL
  170. ----
  171. 0000-01-01 11:59:59 +0000 UTC
  172. query T
  173. SELECT '00:00:00':::TIME - '1s':::INTERVAL
  174. ----
  175. 0000-01-01 23:59:59 +0000 UTC
  176. query T
  177. SELECT '12:00:00':::TIME - '1d':::INTERVAL
  178. ----
  179. 0000-01-01 12:00:00 +0000 UTC
  180. query T
  181. SELECT '12:00:00':::TIME - '11:59:59':::TIME
  182. ----
  183. 00:00:01
  184. query T
  185. SELECT '11:59:59':::TIME - '12:00:00':::TIME
  186. ----
  187. -00:00:01
  188. query T
  189. SELECT '2017-01-01':::DATE + '12:00:00':::TIME
  190. ----
  191. 2017-01-01 12:00:00 +0000 +0000
  192. query T
  193. SELECT '12:00:00':::TIME + '2017-01-01':::DATE
  194. ----
  195. 2017-01-01 12:00:00 +0000 +0000
  196. query T
  197. SELECT '2017-01-01':::DATE - '12:00:00':::TIME
  198. ----
  199. 2016-12-31 12:00:00 +0000 +0000
  200. # Storage
  201. statement ok
  202. CREATE TABLE times (t time PRIMARY KEY)
  203. statement ok
  204. INSERT INTO times VALUES
  205. ('00:00:00'),
  206. ('00:00:00.000001'),
  207. ('11:59:59.999999'),
  208. ('12:00:00'),
  209. ('12:00:00.000001'),
  210. ('23:59:59.999999')
  211. query T
  212. SELECT * FROM times ORDER BY t
  213. ----
  214. 0000-01-01 00:00:00 +0000 UTC
  215. 0000-01-01 00:00:00.000001 +0000 UTC
  216. 0000-01-01 11:59:59.999999 +0000 UTC
  217. 0000-01-01 12:00:00 +0000 UTC
  218. 0000-01-01 12:00:00.000001 +0000 UTC
  219. 0000-01-01 23:59:59.999999 +0000 UTC
  220. statement ok
  221. CREATE TABLE arrays (times TIME[])
  222. statement ok
  223. INSERT INTO arrays VALUES
  224. (ARRAY[]),
  225. (ARRAY['00:00:00']),
  226. (ARRAY['00:00:00', '12:00:00.000001']),
  227. ('{13:00:00}'::TIME[])
  228. query T rowsort
  229. SELECT * FROM arrays
  230. ----
  231. {}
  232. {00:00:00}
  233. {00:00:00,12:00:00.000001}
  234. {13:00:00}
  235. # Built-ins
  236. query T
  237. SELECT date_trunc('hour', time '12:01:02.345678')
  238. ----
  239. 12:00:00
  240. query T
  241. SELECT date_trunc('minute', time '12:01:02.345678')
  242. ----
  243. 12:01:00
  244. query T
  245. SELECT date_trunc('second', time '12:01:02.345678')
  246. ----
  247. 12:01:02
  248. query T
  249. SELECT date_trunc('millisecond', time '12:01:02.345678')
  250. ----
  251. 12:01:02.345
  252. query T
  253. SELECT date_trunc('microsecond', time '12:01:02.345678')
  254. ----
  255. 12:01:02.345678
  256. query error pgcode 22023 date_trunc\(\): unsupported timespan: day
  257. SELECT date_trunc('day', time '12:01:02.345')
  258. query I
  259. SELECT extract(hour from time '12:01:02.345678')
  260. ----
  261. 12
  262. query I
  263. SELECT extract(minute from time '12:01:02.345678')
  264. ----
  265. 1
  266. query I
  267. SELECT extract(second from time '12:01:02.345678')
  268. ----
  269. 2
  270. query I
  271. SELECT extract(millisecond from time '12:01:02.345678')
  272. ----
  273. 345
  274. query I
  275. SELECT extract(microsecond from time '12:01:02.345678')
  276. ----
  277. 345678
  278. query I
  279. SELECT extract(epoch from time '12:00:00')
  280. ----
  281. 43200
  282. query error pgcode 22023 extract\(\): unsupported timespan: day
  283. SELECT extract(day from time '12:00:00')