forked from MaterializeInc/materialize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdates-times.slt
1638 lines (1295 loc) · 37.2 KB
/
dates-times.slt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
mode cockroach
statement ok
CREATE TABLE dateish (
a DATE
)
statement ok
INSERT INTO dateish VALUES (DATE '2000-01-01'), (DATE '2019-12-31')
query T rowsort
SELECT a FROM dateish
----
2000-01-01
2019-12-31
query T
SELECT max(a) FROM dateish
----
2019-12-31
query T
SELECT min(a) FROM dateish
----
2000-01-01
statement ok
CREATE TABLE timestampish (
b timestamp
)
statement ok
INSERT INTO timestampish
VALUES
(TIMESTAMP '1969-06-01 10:10:10.410'),
(TIMESTAMP '1997-02-03 11:12:59.9'),
(TIMESTAMP '2020-01-01 1:2:3.789')
query T rowsort
SELECT b FROM timestampish
----
1969-06-01 10:10:10.41
1997-02-03 11:12:59.9
2020-01-01 01:02:03.789
query T
SELECT max(b) FROM timestampish
----
2020-01-01 01:02:03.789
query T
SELECT min(b) FROM timestampish
----
1969-06-01 10:10:10.41
query T
SELECT INTERVAL '1' MONTH
----
1 month
query T
SELECT INTERVAL '1' YEAR
----
1 year
query T
SELECT INTERVAL '1-3' YEAR TO MONTH
----
1 year 3 months
query T
SELECT INTERVAL '1' MINUTE
----
00:01:00
query T
SELECT INTERVAL '1 MIN'
----
00:01:00
query T
SELECT INTERVAL '1 MINS'
----
00:01:00
query T
SELECT INTERVAL '1 SECS'
----
00:00:01
query T
SELECT INTERVAL '1 SEC'
----
00:00:01
statement ok
CREATE TABLE iv_ish (
b interval
)
statement ok
INSERT INTO iv_ish VALUES (INTERVAL '1' YEAR), (INTERVAL '3' HOUR), (INTERVAL '4d 2h' DAY TO HOUR)
query T rowsort
SELECT * FROM iv_ish
----
4 days 02:00:00
1 year
03:00:00
# Date-time literals
query T
SELECT DATE '2000-01-01'
----
2000-01-01
query T
SELECT DATE '2000 01-01'
----
2000-01-01
query T
SELECT DATE '2000 01 01'
----
2000-01-01
query T
SELECT DATE '20000101'
----
2000-01-01
statement error
SELECT DATE '2000-01 01'
query T
SELECT TIMESTAMP '2000-01-01 01:02:03'
----
2000-01-01 01:02:03
query T
SELECT TIMESTAMP '2000 01-01 01:02:03'
----
2000-01-01 01:02:03
query T
SELECT TIMESTAMP '2000 01 01 01:02:03'
----
2000-01-01 01:02:03
query T
SELECT TIMESTAMP '20010101 01:02:03';
----
2001-01-01 01:02:03
statement error
SELECT TIMESTAMP '2000-01 01 01:02:03'
# Date arithmetic with month intervals.
query T
SELECT DATE '2000-01-01' + INTERVAL '1' MONTH
----
2000-02-01 00:00:00
# Test that DATE + INTERVAL addition works in both orders.
query T
SELECT INTERVAL '1' MONTH + DATE '2000-01-01'
----
2000-02-01 00:00:00
query T
SELECT DATE '2000-01-01' + INTERVAL '1' YEAR
----
2001-01-01 00:00:00
query T
SELECT DATE '2000-01-01' + INTERVAL '-1' MONTH
----
1999-12-01 00:00:00
query T
SELECT DATE '2000-01-01' - INTERVAL '1' MONTH
----
1999-12-01 00:00:00
query T
SELECT DATE '2000-01-01' - INTERVAL '-1' MONTH
----
2000-02-01 00:00:00
query T
SELECT DATE '2000-01-01' - INTERVAL '1' YEAR
----
1999-01-01 00:00:00
query error db error: ERROR: operator does not exist: interval \- date
SELECT INTERVAL '1' YEAR - DATE '2000-01-01'
query T
SELECT DATE '2000-01-01' + TIME '01:02:03'
----
2000-01-01 01:02:03
# Date arithmetic with self. Should behave as interval.
query T
SELECT DATE '2019-02-03' - DATE '2019-01-01';
----
33
# Time arithmetic with intervals.
query T
SELECT TIME '01:02:03' + INTERVAL '04:05:06'
----
05:07:09
query T
SELECT TIME '04:05:06' - INTERVAL '01:02:03'
----
03:03:03
query T
SELECT TIME '01:02:03' - INTERVAL '04:05:06'
----
20:56:57
query T
SELECT TIME '04:05:06' + INTERVAL '-01:02:03'
----
03:03:03
query T
SELECT TIME '01:02:03' - INTERVAL '-04:05:06'
----
05:07:09
# Time arithmetic with self. Should behave as interval
query T
SELECT TIME '04:05:06' - TIME '01:02:03'
----
03:03:03
query T
SELECT TIME '01:02:03' - TIME '04:05:06'
----
-03:03:03
# Timestamp arithmetic with month intervals. Should behave the same as DATE.
query T
SELECT TIMESTAMP '2000-01-01 00:00:00' + INTERVAL '1' YEAR
----
2001-01-01 00:00:00
query T
SELECT TIMESTAMP '2000-01-01 00:00:00' - INTERVAL '1' YEAR
----
1999-01-01 00:00:00
query error db error: ERROR: operator does not exist: interval \- timestamp
SELECT INTERVAL '1' YEAR - TIMESTAMP '2000-01-01 00:00:00'
# Date arithmetic with duration intervals.
query T
SELECT DATE '2000-01-01' + INTERVAL '7' DAY
----
2000-01-08 00:00:00
# Test that DATE + INTERVAL addition works in both orders.
query T
SELECT INTERVAL '7' DAY + DATE '2000-01-01'
----
2000-01-08 00:00:00
query T
SELECT INTERVAL '2 YRS 5 DAYS'
----
2 years 5 days
query T
SELECT INTERVAL '2 YR 5 DAYS'
----
2 years 5 days
query T
SELECT DATE '2000-01-01' + INTERVAL '7 5:4:3.2' DAY TO SECOND
----
2000-01-08 05:04:03.2
query T
SELECT DATE '2000-01-01' + INTERVAL '4' HOUR
----
2000-01-01 04:00:00
query T
SELECT DATE '2000-01-01' + INTERVAL '4 HR'
----
2000-01-01 04:00:00
query T
SELECT DATE '2000-01-01' + INTERVAL '3' MINUTE
----
2000-01-01 00:03:00
query T
SELECT DATE '2000-01-01' + INTERVAL '22' SECOND
----
2000-01-01 00:00:22
query T
SELECT DATE '2000-01-01' + INTERVAL '22.0044' SECOND
----
2000-01-01 00:00:22.0044
query T
SELECT DATE '2000-01-01' - INTERVAL '22' DAY
----
1999-12-10 00:00:00
query T
SELECT DATE '2000-01-01' - INTERVAL '22' SECOND
----
1999-12-31 23:59:38
# Timestamp arithmetic with duration intervals.
query T
SELECT TIMESTAMP '2000-01-01 00:00:00' + INTERVAL '7' HOUR
----
2000-01-01 07:00:00
# date and time comparisons after interval math
query B
SELECT DATE '2000-01-01' < DATE '1999-01-01' + INTERVAL '2' YEAR
----
true
query B
SELECT DATE '2000-01-01' > DATE '1999-01-01' + INTERVAL '2' YEAR
----
false
query B
SELECT DATE '2000-01-01' <= DATE '1999-01-01' + INTERVAL '2' YEAR
----
true
query B
SELECT DATE '2000-01-01' >= DATE '1999-01-01' + INTERVAL '2' YEAR
----
false
query T
SELECT DATE '2001-01-01' + INTERVAL '3' YEAR
----
2004-01-01 00:00:00
# Check Comparisons
query T
SELECT * FROM dateish WHERE a <= DATE '1999-01-01' + INTERVAL '2' YEAR
----
2000-01-01
query T
SELECT * FROM dateish WHERE a < DATE '1999-01-01' + INTERVAL '2' YEAR
----
2000-01-01
query T
SELECT * FROM dateish WHERE a <= DATE '1999-12-31' + INTERVAL '2' DAY
----
2000-01-01
query T
SELECT * FROM dateish WHERE a = DATE '1999-12-31' + INTERVAL '1' DAY
----
2000-01-01
# same as above, but inverted
query T
SELECT * FROM dateish WHERE a >= DATE '1999-01-01' + INTERVAL '2' YEAR
----
2019-12-31
query T
SELECT * FROM dateish WHERE a > DATE '1999-01-01' + INTERVAL '2' YEAR
----
2019-12-31
query T
SELECT * FROM dateish WHERE a >= DATE '1999-12-31' + INTERVAL '2' DAY
----
2019-12-31
query T
SELECT * FROM dateish WHERE a != DATE '1999-12-31' + INTERVAL '1' DAY
----
2019-12-31
query T rowsort
SELECT * FROM dateish WHERE a != DATE '1999-12-31' + INTERVAL '2' DAY
----
2000-01-01
2019-12-31
# Comparisons with timestamps
statement ok
CREATE TABLE timestamp_compares (
c timestamp
)
statement ok
INSERT INTO timestamp_compares
VALUES
(TIMESTAMP '1999-12-31 01:01:01'),
(TIMESTAMP '2009-01-01 09:09:09.9')
query T
SELECT c FROM timestamp_compares WHERE c = TIMESTAMP '2009-01-01 09:09:09.9'
----
2009-01-01 09:09:09.9
query T
SELECT c FROM timestamp_compares WHERE c = TIMESTAMP '2008-12-31 09:09:09.9' + INTERVAL '1' DAY
----
2009-01-01 09:09:09.9
query T
SELECT c FROM timestamp_compares WHERE c = TIMESTAMP '2008-12-01 09:09:09.9' + INTERVAL '1' MONTH
----
2009-01-01 09:09:09.9
query T rowsort
SELECT c FROM timestamp_compares WHERE c < TIMESTAMP '2008-12-31 09:09:09.9' + INTERVAL '2' MONTH
----
1999-12-31 01:01:01
2009-01-01 09:09:09.9
# some inverses
query T
SELECT c FROM timestamp_compares WHERE c != TIMESTAMP '2009-01-01 09:09:09.9'
----
1999-12-31 01:01:01
query T
SELECT c FROM timestamp_compares WHERE c != TIMESTAMP '2008-12-31 09:09:09.9' + INTERVAL '1' DAY
----
1999-12-31 01:01:01
query T
SELECT c FROM timestamp_compares WHERE c != TIMESTAMP '2008-12-01 09:09:09.9' + INTERVAL '1' MONTH
----
1999-12-31 01:01:01
query T rowsort
SELECT c FROM timestamp_compares WHERE c > TIMESTAMP '2008-12-31 09:09:09.9' + INTERVAL '2' MONTH
----
statement ok
CREATE TABLE timestampwithtzish (
t timestamp
)
statement ok
INSERT INTO timestampwithtzish
VALUES
(TIMESTAMP WITH TIME ZONE '1999-12-31 11:11:01+04:00'),
(TIMESTAMP WITH TIME ZONE '1999-12-31 16:16:01+02:30'),
(TIMESTAMP WITH TIME ZONE '1999-12-31 20:00:00-12'),
(TIMESTAMP WITH TIME ZONE '1999-12-31 18:00:00+12')
query T rowsort
SELECT * FROM timestampwithtzish
----
1999-12-31 06:00:00
1999-12-31 07:11:01
1999-12-31 13:46:01
2000-01-01 08:00:00
statement ok
CREATE TABLE timestamptzish (
t timestamptz
)
statement ok
INSERT INTO timestamptzish
VALUES
(TIMESTAMPTZ '1999-12-31 11:11:01+04:00'),
(TIMESTAMPTZ '1999-12-31 16:16:01+02:30'),
(TIMESTAMPTZ '1999-12-31 20:00:00-12'),
(TIMESTAMPTZ '1999-12-31 18:00:00+12')
query T rowsort
SELECT * FROM timestamptzish
----
1999-12-31 06:00:00+00
1999-12-31 07:11:01+00
1999-12-31 13:46:01+00
2000-01-01 08:00:00+00
query T
SELECT max(t) FROM timestamptzish
----
2000-01-01 08:00:00+00
query T
SELECT min(t) FROM timestamptzish
----
1999-12-31 06:00:00+00
# Timestamptz arithmetic with month intervals. Should behave the same as DATE and timestamp
query T
SELECT TIMESTAMPTZ '2000-01-01 00:00:00-6' + INTERVAL '1' YEAR
----
2001-01-01 06:00:00+00
query T
SELECT TIMESTAMPTZ '2000-01-01 00:00:00-7' - INTERVAL '1' YEAR
----
1999-01-01 07:00:00+00
query T
SELECT TIMESTAMPTZ '2000-01-01 00:00:00-6' + INTERVAL '3' MONTH
----
2000-04-01 06:00:00+00
query T
SELECT TIMESTAMPTZ '2000-01-01 00:00:00-7' - INTERVAL '4' MONTH
----
1999-09-01 07:00:00+00
query error db error: ERROR: operator does not exist: interval \- timestamp with time zone
SELECT INTERVAL '1' YEAR - TIMESTAMPTZ '2000-01-01 00:00:00-4:00'
# Timestamptz arithmetic with duration intervals.
query T
SELECT TIMESTAMPTZ '2000-01-01 00:00:00-04' + INTERVAL '7' HOUR
----
2000-01-01 11:00:00+00
query T
SELECT TIMESTAMPTZ '2000-01-01 00:00:00-04' + INTERVAL '3' MINUTE
----
2000-01-01 04:03:00+00
query T
SELECT INTERVAL '6' HOUR + TIMESTAMPTZ '2000-01-01 00:00:00-04'
----
2000-01-01 10:00:00+00
query T
SELECT TIMESTAMPTZ '2000-01-01 00:00:00-04' - INTERVAL '2' HOUR
----
2000-01-01 02:00:00+00
query error db error: ERROR: operator does not exist: interval \- timestamp with time zone
SELECT INTERVAL '2' HOUR - TIMESTAMPTZ '2000-01-01 00:00:00-04'
query error db error: ERROR: operator does not exist: timestamp with time zone \* interval
SELECT TIMESTAMPTZ '2000-01-01 00:00:00-04' * INTERVAL '2' HOUR
query error db error: ERROR: operator does not exist: timestamp with time zone / interval
SELECT TIMESTAMPTZ '2000-01-01 00:00:00-04' / INTERVAL '2' HOUR
query error db error: ERROR: operator does not exist: timestamp with time zone \+ timestamp with time zone
SELECT TIMESTAMPTZ '2000-01-01 00:00:00-04' + TIMESTAMPTZ '1999-01-01 00:00:00z'
query error db error: ERROR: operator does not exist: timestamp with time zone \+ timestamp
SELECT TIMESTAMPTZ '2000-01-01 00:00:00-04' + TIMESTAMP '1999-01-01 00:00:00'
# Tests with comparison operators and timestamptz
query B
SELECT TIMESTAMPTZ '2000-01-01 00:00:00+01' < TIMESTAMPTZ '2000-01-01 00:00:00-04'
----
true
query B
SELECT TIMESTAMPTZ '2000-01-01 00:00:00+01' > TIMESTAMPTZ '2000-01-01 00:00:00-04'
----
false
query B
SELECT TIMESTAMPTZ '2000-01-01 00:00:00+01' <= TIMESTAMPTZ '2000-01-01 00:00:00-04'
----
true
query B
SELECT TIMESTAMPTZ '2000-01-01 00:00:00+01' >= TIMESTAMPTZ '2000-01-01 00:00:00-04'
----
false
query B
SELECT TIMESTAMPTZ '2000-01-01 02:00:00+01' = TIMESTAMPTZ '2000-01-01 01:00:00z'
----
true
query B
SELECT TIMESTAMPTZ '2000-01-01 02:00:00+01' >= TIMESTAMPTZ '2000-01-01 01:00:00z'
----
true
query B
SELECT TIMESTAMPTZ '2000-01-01 02:00:00+01' <= TIMESTAMPTZ '2000-01-01 01:00:00z'
----
true
query B
SELECT TIMESTAMPTZ '2000-01-01 02:00:00+01' != TIMESTAMPTZ '2000-01-01 01:00:00z'
----
false
# Tests with comparison operators across different time types
query B
SELECT TIMESTAMP '2000-01-01 00:00:00' > DATE '2000-01-01'
----
false
query B
SELECT TIMESTAMPTZ '2000-01-01 00:00:00+4' > DATE '2000-01-01'
----
false
query B
SELECT DATE '2001-01-01' > TIMESTAMPTZ '2000-01-01 00:00:00+4'
----
true
query B
SELECT TIMESTAMPTZ '2000-01-01 00:00:00+4' > TIMESTAMP '2000-01-01 01:00:00'
----
false
query B
SELECT TIMESTAMP '2000-01-01 00:00:00' > TIMESTAMPTZ '2000-01-01 01:00:00+04'
----
true
# Timestamptz comparisons after interval math
query B
SELECT TIMESTAMPTZ '2000-01-01 01:00:00+01' < TIMESTAMPTZ '2000-01-01 00:01:00z' + INTERVAL '1' HOUR
----
true
query B
SELECT TIMESTAMPTZ '2000-01-01 01:00:00+01' <= TIMESTAMPTZ '2000-01-01 00:01:00z' + INTERVAL '1' HOUR
----
true
query B
SELECT TIMESTAMPTZ '2000-01-01 01:00:00+01' > TIMESTAMPTZ '2000-01-01 00:01:00z' + INTERVAL '1' HOUR
----
false
query B
SELECT TIMESTAMPTZ '2000-01-01 01:00:00+01' >= TIMESTAMPTZ '2000-01-01 00:01:00z' + INTERVAL '1' HOUR
----
false
query B
SELECT TIMESTAMPTZ '2000-01-01 01:00:00+01' + INTERVAL '3' HOUR > TIMESTAMPTZ '2000-01-01 00:01:00z' + INTERVAL '1' HOUR
----
true
query B
SELECT TIMESTAMPTZ '2000-01-01 01:00:00+01' + INTERVAL '1' MINUTE != TIMESTAMPTZ '2000-01-01 00:01:00+01' + INTERVAL '1' HOUR
----
false
# comparisons with timestamptz
query T
SELECT t FROM timestamptzish WHERE t = TIMESTAMPTZ '1999-12-31 13:46:01z'
----
1999-12-31 13:46:01+00
query T
SELECT t FROM timestamptzish WHERE t = TIMESTAMP '1999-12-31 13:46:01'
----
1999-12-31 13:46:01+00
query T
SELECT t FROM timestamptzish WHERE t = TIMESTAMPTZ '1999-12-31 9:46:01-04'
----
1999-12-31 13:46:01+00
query T
SELECT t FROM timestamptzish WHERE t > TIMESTAMPTZ '1999-12-31 9:46:01-04'
----
2000-01-01 08:00:00+00
query T rowsort
SELECT t FROM timestamptzish WHERE t >= TIMESTAMPTZ '1999-12-31 9:46:01-04'
----
1999-12-31 13:46:01+00
2000-01-01 08:00:00+00
query T rowsort
SELECT t FROM timestamptzish WHERE t < TIMESTAMPTZ '1999-12-31 9:46:01-04'
----
1999-12-31 06:00:00+00
1999-12-31 07:11:01+00
query T rowsort
SELECT t FROM timestamptzish WHERE t <= TIMESTAMPTZ '1999-12-31 9:46:01-04'
----
1999-12-31 06:00:00+00
1999-12-31 07:11:01+00
1999-12-31 13:46:01+00
query T rowsort
SELECT t FROM timestamptzish WHERE t > TIMESTAMPTZ '1999-12-31 9:46:01-04' - INTERVAL '12' HOUR
----
1999-12-31 06:00:00+00
1999-12-31 07:11:01+00
1999-12-31 13:46:01+00
2000-01-01 08:00:00+00
# Tests now() and current_timestamp()
query B
SELECT now() > timestamp '2015-06-13 00:00:00'
----
true
query B
SELECT now() + INTERVAL '100' HOUR > now()
----
true
query B
SELECT current_timestamp() > TIMESTAMP '2016-06-13 00:00:00'
----
true
query B
SELECT current_timestamp > TIMESTAMP '2016-06-13 00:00:00'
----
true
statement ok
CREATE VIEW logical_timestamp_view(ts) AS SELECT mz_now()
# Equivalent to running `SELECT mz_now()` directly. If there are
# other objects in the same time domain as the view, they will dictate what is
# returned. Otherwise it defaults to the epoch millisecond timeline.
query T
SELECT ts < 18446744073709551615 FROM logical_timestamp_view
----
true
statement ok
CREATE VIEW now_view AS SELECT now() AS ts
query B
SELECT ts > TIMESTAMP '2016-06-13 00:00:00' FROM now_view
----
true
query T
SELECT (DATE '2000-01-01')::text
----
2000-01-01
query T
SELECT (TIMESTAMP '2000-01-01 00:00:00')::text
----
2000-01-01 00:00:00
query T
SELECT (TIMESTAMPTZ '2000-01-01 00:00:00-6')::text
----
2000-01-01 06:00:00+00
query T
SELECT (INTERVAL '1-3' YEAR TO MONTH)::text
----
1 year 3 months
query RRRRR
SELECT EXTRACT(HOUR from TIME '11:12:42.666'),
EXTRACT(MINUTE from TIME '11:12:42.666'),
EXTRACT(SECOND from TIME '11:12:42.666'),
EXTRACT(MILLISECONDS from TIME '11:12:42.666'),
EXTRACT(MICROSECONDS from TIME '11:12:42.666')
----
11 12 42.666 42666 42666000
query RRRRR
SELECT date_part('HOUR', TIME '11:12:42.666'),
date_part('MINUTE', TIME '11:12:42.666'),
date_part('SECOND', TIME '11:12:42.666'),
date_part('MILLISECONDS', TIME '11:12:42.666'),
date_part('MICROSECONDS', TIME '11:12:42.666')
----
11 12 42.666 42666 42666000
query error unit 'millennium' not supported for type time
SELECT EXTRACT(MILLENNIUM from TIME '11:12:42.666')
query error unit 'century' not supported for type time
SELECT EXTRACT(CENTURY from TIME '11:12:42.666')
query error unit 'decade' not supported for type time
SELECT EXTRACT(DECADE from TIME '11:12:42.666')
query error unit 'year' not supported for type time
SELECT EXTRACT(YEAR from TIME '11:12:42.666')
query error unit 'quarter' not supported for type time
SELECT EXTRACT(QUARTER from TIME '11:12:42.666')
query error unit 'month' not supported for type time
SELECT EXTRACT(MONTH from TIME '11:12:42.666')
query error unit 'week' not supported for type time
SELECT EXTRACT(WEEK from TIME '11:12:42.666')
query error unit 'day' not supported for type time
SELECT EXTRACT(DAY from TIME '11:12:42.666')
query error unit 'dow' not supported for type time
SELECT EXTRACT(DOW from TIME '11:12:42.666')
query error unit 'doy' not supported for type time
SELECT EXTRACT(DOY from TIME '11:12:42.666')
query error unit 'isodow' not supported for type time
SELECT EXTRACT(ISODOW from TIME '11:12:42.666')
query error unit 'isodoy' not supported for type time
SELECT EXTRACT(ISODOY from TIME '11:12:42.666')
query error unit 'month' not supported for type time
SELECT date_part('MONTH', TIME '11:12:42.666')
query RR
SELECT EXTRACT(DOW FROM TIMESTAMP '1999-12-26 00:00:00'), EXTRACT(DOW FROM TIMESTAMP '2000-01-01 00:00:00')
----
0 6
query RR
SELECT EXTRACT(ISODOW FROM TIMESTAMP '1999-12-26 00:00:00'), EXTRACT(ISODOW FROM TIMESTAMP '2000-01-01 00:00:00')
----
7 6
query RRRRRRRRRRRRRRRRR
SELECT EXTRACT(EPOCH FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(MILLENNIUM FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(CENTURY FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(DECADE FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(YEAR FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(QUARTER FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(WEEK FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(MONTH FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(HOUR FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(DAY FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(DOW FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(DOY FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(ISODOW FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(MINUTE FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(SECOND FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(MS FROM TIMESTAMP '2019-11-26 15:56:46.241150'),
EXTRACT(US FROM TIMESTAMP '2019-11-26 15:56:46.241150')
----
1574783806.24115 3 21 201 2019 4 48 11 15 26 2 330 2 56 46.24115 46241.15 46241150
query RRRRRRRRRRRRRRRRR
SELECT date_part('EPOCH', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('MILLENNIUM', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('CENTURY', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('DECADE', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('YEAR', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('QUARTER', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('WEEK', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('MONTH', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('HOUR', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('DAY', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('DOW', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('DOY', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('ISODOW', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('MINUTE', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('SECOND', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('MS', TIMESTAMP '2019-11-26 15:56:46.241150'),
date_part('US', TIMESTAMP '2019-11-26 15:56:46.241150')
----
1574783806.24115 3 21 201 2019 4 48 11 15 26 2 330 2 56 46.24115 46241.15 46241150
query RRRRRRRRRRRR
SELECT EXTRACT(QUARTER FROM DATE '2000-01-01'),
EXTRACT(QUARTER FROM DATE '2000-02-03'),
EXTRACT(QUARTER FROM DATE '2000-03-05'),
EXTRACT(QUARTER FROM DATE '2000-04-07'),
EXTRACT(QUARTER FROM DATE '2000-05-09'),
EXTRACT(QUARTER FROM DATE '2000-06-11'),
EXTRACT(QUARTER FROM DATE '2000-07-13'),
EXTRACT(QUARTER FROM DATE '2000-08-15'),
EXTRACT(QUARTER FROM DATE '2000-09-17'),
EXTRACT(QUARTER FROM DATE '2000-10-19'),
EXTRACT(QUARTER FROM DATE '2000-11-21'),
EXTRACT(QUARTER FROM DATE '2000-12-24')
----
1 1 1 2 2 2 3 3 3 4 4 4
query RRRRRRRR
SELECT EXTRACT(MILLENNIUM FROM DATE '2001-01-01'),
EXTRACT(MILLENNIUM FROM DATE '2000-01-01'),
EXTRACT(MILLENNIUM FROM DATE '1999-01-01'),
EXTRACT(MILLENNIUM FROM DATE '1001-01-01'),
EXTRACT(MILLENNIUM FROM DATE '1000-01-01'),
EXTRACT(MILLENNIUM FROM DATE '0001-01-01'),
EXTRACT(MILLENNIUM FROM DATE '0001-01-01' - INTERVAL '1'SECOND),
EXTRACT(MILLENNIUM FROM DATE '0001-01-01' - INTERVAL '1000 YEAR 1 SECOND')
----
3 2 2 2 1 1 -1 -2
query RRRRRRRR
SELECT EXTRACT(CENTURY FROM DATE '2001-01-01'),
EXTRACT(CENTURY FROM DATE '2000-01-01'),
EXTRACT(CENTURY FROM DATE '1999-01-01'),
EXTRACT(CENTURY FROM DATE '1001-01-01'),
EXTRACT(CENTURY FROM DATE '1000-01-01'),
EXTRACT(CENTURY FROM DATE '0001-01-01'),
EXTRACT(CENTURY FROM DATE '0001-01-01' - INTERVAL '1'SECOND),
EXTRACT(CENTURY FROM DATE '0001-01-01' - INTERVAL '100 YEAR 1 SECOND')
----
21 20 20 11 10 1 -1 -2
query RRRRRRRR
SELECT EXTRACT(DECADE FROM DATE '2001-01-01'),
EXTRACT(DECADE FROM DATE '2000-01-01'),
EXTRACT(DECADE FROM DATE '1999-01-01'),
EXTRACT(DECADE FROM DATE '0001-01-01'),
EXTRACT(DECADE FROM DATE '0001-01-01' - INTERVAL '1'SECOND),
EXTRACT(DECADE FROM DATE '0001-01-01' - INTERVAL '1 YEAR 1 SECOND'),
EXTRACT(DECADE FROM DATE '0001-01-01' - INTERVAL '10 YEAR 1 SECOND'),
EXTRACT(DECADE FROM DATE '0001-01-01' - INTERVAL '11 YEAR 1 SECOND')
----
200 200 199 0 0 -1 -1 -2
query RR
SELECT EXTRACT(WEEK FROM DATE '2000-01-01'), EXTRACT(WEEK FROM DATE '2000-01-08')
----
52 1
query RR
SELECT EXTRACT(DOY FROM DATE '2000-01-01'), EXTRACT(DOY FROM DATE '2000-12-31')
----
1 366
query error unit 'hour' not supported for type date
SELECT EXTRACT(HOUR FROM DATE '2000-12-31')
query error unit 'seconds' not supported for type date
SELECT EXTRACT(SECOND FROM DATE '2000-12-31')
query error unit 'milliseconds' not supported for type date
SELECT EXTRACT(MILLISECOND FROM DATE '2000-12-31')
query error unit 'microseconds' not supported for type date
SELECT EXTRACT(MICROSECOND FROM DATE '2000-12-31')
query RRRR
SELECT date_part('HOUR', DATE '2000-12-31'),
date_part('SECOND', DATE '2000-12-31'),
date_part('MILLISECOND', DATE '2000-12-31'),
date_part('MICROSECOND', DATE '2000-12-31')
----
0 0 0 0
query RR
SELECT EXTRACT(EPOCH from INTERVAL '-1' MINUTE), EXTRACT(MINUTE from INTERVAL '-1' MINUTE)
----
-60 -1
query RR
SELECT EXTRACT(EPOCH from INTERVAL '1' YEAR), EXTRACT(EPOCH from INTERVAL '1' MONTH) * 12
----