summaryrefslogtreecommitdiffstats
path: root/src/test/regress/expected/interval.out
blob: 9fc9b0f087f15dc79ce165e15514a5ebbc50289b (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
--
-- INTERVAL
--
SET DATESTYLE = 'ISO';
SET IntervalStyle to postgres;
-- check acceptance of "time zone style"
SELECT INTERVAL '01:00' AS "One hour";
 One hour 
----------
 01:00:00
(1 row)

SELECT INTERVAL '+02:00' AS "Two hours";
 Two hours 
-----------
 02:00:00
(1 row)

SELECT INTERVAL '-08:00' AS "Eight hours";
 Eight hours 
-------------
 -08:00:00
(1 row)

SELECT INTERVAL '-1 +02:03' AS "22 hours ago...";
  22 hours ago...  
-------------------
 -1 days +02:03:00
(1 row)

SELECT INTERVAL '-1 days +02:03' AS "22 hours ago...";
  22 hours ago...  
-------------------
 -1 days +02:03:00
(1 row)

SELECT INTERVAL '1.5 weeks' AS "Ten days twelve hours";
 Ten days twelve hours 
-----------------------
 10 days 12:00:00
(1 row)

SELECT INTERVAL '1.5 months' AS "One month 15 days";
 One month 15 days 
-------------------
 1 mon 15 days
(1 row)

SELECT INTERVAL '10 years -11 month -12 days +13:14' AS "9 years...";
            9 years...            
----------------------------------
 9 years 1 mon -12 days +13:14:00
(1 row)

CREATE TABLE INTERVAL_TBL (f1 interval);
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 1 minute');
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 5 hour');
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 10 day');
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 34 year');
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 3 months');
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 14 seconds ago');
INSERT INTO INTERVAL_TBL (f1) VALUES ('1 day 2 hours 3 minutes 4 seconds');
INSERT INTO INTERVAL_TBL (f1) VALUES ('6 years');
INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months');
INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months 12 hours');
-- badly formatted interval
INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted interval');
ERROR:  invalid input syntax for type interval: "badly formatted interval"
LINE 1: INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted inter...
                                              ^
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
ERROR:  invalid input syntax for type interval: "@ 30 eons ago"
LINE 1: INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
                                              ^
-- Test non-error-throwing API
SELECT pg_input_is_valid('1.5 weeks', 'interval');
 pg_input_is_valid 
-------------------
 t
(1 row)

SELECT pg_input_is_valid('garbage', 'interval');
 pg_input_is_valid 
-------------------
 f
(1 row)

SELECT pg_input_is_valid('@ 30 eons ago', 'interval');
 pg_input_is_valid 
-------------------
 f
(1 row)

SELECT * FROM pg_input_error_info('garbage', 'interval');
                      message                      | detail | hint | sql_error_code 
---------------------------------------------------+--------+------+----------------
 invalid input syntax for type interval: "garbage" |        |      | 22007
(1 row)

SELECT * FROM pg_input_error_info('@ 30 eons ago', 'interval');
                         message                         | detail | hint | sql_error_code 
---------------------------------------------------------+--------+------+----------------
 invalid input syntax for type interval: "@ 30 eons ago" |        |      | 22007
(1 row)

-- test interval operators
SELECT * FROM INTERVAL_TBL;
       f1        
-----------------
 00:01:00
 05:00:00
 10 days
 34 years
 3 mons
 -00:00:14
 1 day 02:03:04
 6 years
 5 mons
 5 mons 12:00:00
(10 rows)

SELECT * FROM INTERVAL_TBL
   WHERE INTERVAL_TBL.f1 <> interval '@ 10 days';
       f1        
-----------------
 00:01:00
 05:00:00
 34 years
 3 mons
 -00:00:14
 1 day 02:03:04
 6 years
 5 mons
 5 mons 12:00:00
(9 rows)

SELECT * FROM INTERVAL_TBL
   WHERE INTERVAL_TBL.f1 <= interval '@ 5 hours';
    f1     
-----------
 00:01:00
 05:00:00
 -00:00:14
(3 rows)

SELECT * FROM INTERVAL_TBL
   WHERE INTERVAL_TBL.f1 < interval '@ 1 day';
    f1     
-----------
 00:01:00
 05:00:00
 -00:00:14
(3 rows)

SELECT * FROM INTERVAL_TBL
   WHERE INTERVAL_TBL.f1 = interval '@ 34 years';
    f1    
----------
 34 years
(1 row)

SELECT * FROM INTERVAL_TBL
   WHERE INTERVAL_TBL.f1 >= interval '@ 1 month';
       f1        
-----------------
 34 years
 3 mons
 6 years
 5 mons
 5 mons 12:00:00
(5 rows)

SELECT * FROM INTERVAL_TBL
   WHERE INTERVAL_TBL.f1 > interval '@ 3 seconds ago';
       f1        
-----------------
 00:01:00
 05:00:00
 10 days
 34 years
 3 mons
 1 day 02:03:04
 6 years
 5 mons
 5 mons 12:00:00
(9 rows)

SELECT r1.*, r2.*
   FROM INTERVAL_TBL r1, INTERVAL_TBL r2
   WHERE r1.f1 > r2.f1
   ORDER BY r1.f1, r2.f1;
       f1        |       f1        
-----------------+-----------------
 00:01:00        | -00:00:14
 05:00:00        | -00:00:14
 05:00:00        | 00:01:00
 1 day 02:03:04  | -00:00:14
 1 day 02:03:04  | 00:01:00
 1 day 02:03:04  | 05:00:00
 10 days         | -00:00:14
 10 days         | 00:01:00
 10 days         | 05:00:00
 10 days         | 1 day 02:03:04
 3 mons          | -00:00:14
 3 mons          | 00:01:00
 3 mons          | 05:00:00
 3 mons          | 1 day 02:03:04
 3 mons          | 10 days
 5 mons          | -00:00:14
 5 mons          | 00:01:00
 5 mons          | 05:00:00
 5 mons          | 1 day 02:03:04
 5 mons          | 10 days
 5 mons          | 3 mons
 5 mons 12:00:00 | -00:00:14
 5 mons 12:00:00 | 00:01:00
 5 mons 12:00:00 | 05:00:00
 5 mons 12:00:00 | 1 day 02:03:04
 5 mons 12:00:00 | 10 days
 5 mons 12:00:00 | 3 mons
 5 mons 12:00:00 | 5 mons
 6 years         | -00:00:14
 6 years         | 00:01:00
 6 years         | 05:00:00
 6 years         | 1 day 02:03:04
 6 years         | 10 days
 6 years         | 3 mons
 6 years         | 5 mons
 6 years         | 5 mons 12:00:00
 34 years        | -00:00:14
 34 years        | 00:01:00
 34 years        | 05:00:00
 34 years        | 1 day 02:03:04
 34 years        | 10 days
 34 years        | 3 mons
 34 years        | 5 mons
 34 years        | 5 mons 12:00:00
 34 years        | 6 years
(45 rows)

-- Test intervals that are large enough to overflow 64 bits in comparisons
CREATE TEMP TABLE INTERVAL_TBL_OF (f1 interval);
INSERT INTO INTERVAL_TBL_OF (f1) VALUES
  ('2147483647 days 2147483647 months'),
  ('2147483647 days -2147483648 months'),
  ('1 year'),
  ('-2147483648 days 2147483647 months'),
  ('-2147483648 days -2147483648 months');
-- these should fail as out-of-range
INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483648 days');
ERROR:  interval field value out of range: "2147483648 days"
LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483648 days');
                                                 ^
INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483649 days');
ERROR:  interval field value out of range: "-2147483649 days"
LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483649 days')...
                                                 ^
INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483647 years');
ERROR:  interval out of range
LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483647 years')...
                                                 ^
INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483648 years');
ERROR:  interval out of range
LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483648 years'...
                                                 ^
-- Test edge-case overflow detection in interval multiplication
select extract(epoch from '256 microseconds'::interval * (2^55)::float8);
ERROR:  interval out of range
SELECT r1.*, r2.*
   FROM INTERVAL_TBL_OF r1, INTERVAL_TBL_OF r2
   WHERE r1.f1 > r2.f1
   ORDER BY r1.f1, r2.f1;
                    f1                     |                    f1                     
-------------------------------------------+-------------------------------------------
 -178956970 years -8 mons +2147483647 days | -178956970 years -8 mons -2147483648 days
 1 year                                    | -178956970 years -8 mons -2147483648 days
 1 year                                    | -178956970 years -8 mons +2147483647 days
 178956970 years 7 mons -2147483648 days   | -178956970 years -8 mons -2147483648 days
 178956970 years 7 mons -2147483648 days   | -178956970 years -8 mons +2147483647 days
 178956970 years 7 mons -2147483648 days   | 1 year
 178956970 years 7 mons 2147483647 days    | -178956970 years -8 mons -2147483648 days
 178956970 years 7 mons 2147483647 days    | -178956970 years -8 mons +2147483647 days
 178956970 years 7 mons 2147483647 days    | 1 year
 178956970 years 7 mons 2147483647 days    | 178956970 years 7 mons -2147483648 days
(10 rows)

CREATE INDEX ON INTERVAL_TBL_OF USING btree (f1);
SET enable_seqscan TO false;
EXPLAIN (COSTS OFF)
SELECT f1 FROM INTERVAL_TBL_OF r1 ORDER BY f1;
                             QUERY PLAN                             
--------------------------------------------------------------------
 Index Only Scan using interval_tbl_of_f1_idx on interval_tbl_of r1
(1 row)

SELECT f1 FROM INTERVAL_TBL_OF r1 ORDER BY f1;
                    f1                     
-------------------------------------------
 -178956970 years -8 mons -2147483648 days
 -178956970 years -8 mons +2147483647 days
 1 year
 178956970 years 7 mons -2147483648 days
 178956970 years 7 mons 2147483647 days
(5 rows)

RESET enable_seqscan;
DROP TABLE INTERVAL_TBL_OF;
-- Test multiplication and division with intervals.
-- Floating point arithmetic rounding errors can lead to unexpected results,
-- though the code attempts to do the right thing and round up to days and
-- minutes to avoid results such as '3 days 24:00 hours' or '14:20:60'.
-- Note that it is expected for some day components to be greater than 29 and
-- some time components be greater than 23:59:59 due to how intervals are
-- stored internally.
CREATE TABLE INTERVAL_MULDIV_TBL (span interval);
COPY INTERVAL_MULDIV_TBL FROM STDIN;
SELECT span * 0.3 AS product
FROM INTERVAL_MULDIV_TBL;
              product               
------------------------------------
 1 year 12 days 122:24:00
 -1 years -12 days +93:36:00
 -3 days -14:24:00
 2 mons 13 days 01:22:28.8
 -10 mons +120 days 37:28:21.6567
 1 mon 6 days
 4 mons 6 days
 24 years 11 mons 320 days 16:48:00
(8 rows)

SELECT span * 8.2 AS product
FROM INTERVAL_MULDIV_TBL;
                   product                   
---------------------------------------------
 28 years 104 days 2961:36:00
 -28 years -104 days +2942:24:00
 -98 days -09:36:00
 6 years 1 mon -197 days +93:34:27.2
 -24 years -7 mons +3946 days 640:15:11.9498
 2 years 8 mons 24 days
 9 years 6 mons 24 days
 682 years 7 mons 8215 days 19:12:00
(8 rows)

SELECT span / 10 AS quotient
FROM INTERVAL_MULDIV_TBL;
             quotient             
----------------------------------
 4 mons 4 days 40:48:00
 -4 mons -4 days +31:12:00
 -1 days -04:48:00
 25 days -15:32:30.4
 -3 mons +30 days 12:29:27.2189
 12 days
 1 mon 12 days
 8 years 3 mons 126 days 21:36:00
(8 rows)

SELECT span / 100 AS quotient
FROM INTERVAL_MULDIV_TBL;
        quotient         
-------------------------
 12 days 13:40:48
 -12 days -06:28:48
 -02:52:48
 2 days 10:26:44.96
 -6 days +01:14:56.72189
 1 day 04:48:00
 4 days 04:48:00
 9 mons 39 days 16:33:36
(8 rows)

DROP TABLE INTERVAL_MULDIV_TBL;
SET DATESTYLE = 'postgres';
SET IntervalStyle to postgres_verbose;
SELECT * FROM INTERVAL_TBL;
              f1               
-------------------------------
 @ 1 min
 @ 5 hours
 @ 10 days
 @ 34 years
 @ 3 mons
 @ 14 secs ago
 @ 1 day 2 hours 3 mins 4 secs
 @ 6 years
 @ 5 mons
 @ 5 mons 12 hours
(10 rows)

-- multiplication and division overflow test cases
SELECT '3000000 months'::interval * 1000;
ERROR:  interval out of range
SELECT '3000000 months'::interval / 0.001;
ERROR:  interval out of range
SELECT '3000000 days'::interval * 1000;
ERROR:  interval out of range
SELECT '3000000 days'::interval / 0.001;
ERROR:  interval out of range
SELECT '1 month 2146410 days'::interval * 1000.5002;
ERROR:  interval out of range
SELECT '4611686018427387904 usec'::interval / 0.1;
ERROR:  interval out of range
-- test avg(interval), which is somewhat fragile since people have been
-- known to change the allowed input syntax for type interval without
-- updating pg_aggregate.agginitval
select avg(f1) from interval_tbl;
                       avg                       
-------------------------------------------------
 @ 4 years 1 mon 10 days 4 hours 18 mins 23 secs
(1 row)

-- test long interval input
select '4 millenniums 5 centuries 4 decades 1 year 4 months 4 days 17 minutes 31 seconds'::interval;
                  interval                  
--------------------------------------------
 @ 4541 years 4 mons 4 days 17 mins 31 secs
(1 row)

-- test long interval output
-- Note: the actual maximum length of the interval output is longer,
-- but we need the test to work for both integer and floating-point
-- timestamps.
select '100000000y 10mon -1000000000d -100000h -10min -10.000001s ago'::interval;
                                       interval                                        
---------------------------------------------------------------------------------------
 @ 100000000 years 10 mons -1000000000 days -100000 hours -10 mins -10.000001 secs ago
(1 row)

-- test justify_hours() and justify_days()
SELECT justify_hours(interval '6 months 3 days 52 hours 3 minutes 2 seconds') as "6 mons 5 days 4 hours 3 mins 2 seconds";
 6 mons 5 days 4 hours 3 mins 2 seconds 
----------------------------------------
 @ 6 mons 5 days 4 hours 3 mins 2 secs
(1 row)

SELECT justify_days(interval '6 months 36 days 5 hours 4 minutes 3 seconds') as "7 mons 6 days 5 hours 4 mins 3 seconds";
 7 mons 6 days 5 hours 4 mins 3 seconds 
----------------------------------------
 @ 7 mons 6 days 5 hours 4 mins 3 secs
(1 row)

SELECT justify_hours(interval '2147483647 days 24 hrs');
ERROR:  interval out of range
SELECT justify_days(interval '2147483647 months 30 days');
ERROR:  interval out of range
-- test justify_interval()
SELECT justify_interval(interval '1 month -1 hour') as "1 month -1 hour";
  1 month -1 hour   
--------------------
 @ 29 days 23 hours
(1 row)

SELECT justify_interval(interval '2147483647 days 24 hrs');
       justify_interval        
-------------------------------
 @ 5965232 years 4 mons 8 days
(1 row)

SELECT justify_interval(interval '-2147483648 days -24 hrs');
         justify_interval          
-----------------------------------
 @ 5965232 years 4 mons 9 days ago
(1 row)

SELECT justify_interval(interval '2147483647 months 30 days');
ERROR:  interval out of range
SELECT justify_interval(interval '-2147483648 months -30 days');
ERROR:  interval out of range
SELECT justify_interval(interval '2147483647 months 30 days -24 hrs');
         justify_interval         
----------------------------------
 @ 178956970 years 7 mons 29 days
(1 row)

SELECT justify_interval(interval '-2147483648 months -30 days 24 hrs');
           justify_interval           
--------------------------------------
 @ 178956970 years 8 mons 29 days ago
(1 row)

SELECT justify_interval(interval '2147483647 months -30 days 1440 hrs');
ERROR:  interval out of range
SELECT justify_interval(interval '-2147483648 months 30 days -1440 hrs');
ERROR:  interval out of range
-- test fractional second input, and detection of duplicate units
SET DATESTYLE = 'ISO';
SET IntervalStyle TO postgres;
SELECT '1 millisecond'::interval, '1 microsecond'::interval,
       '500 seconds 99 milliseconds 51 microseconds'::interval;
   interval   |    interval     |    interval     
--------------+-----------------+-----------------
 00:00:00.001 | 00:00:00.000001 | 00:08:20.099051
(1 row)

SELECT '3 days 5 milliseconds'::interval;
      interval       
---------------------
 3 days 00:00:00.005
(1 row)

SELECT '1 second 2 seconds'::interval;              -- error
ERROR:  invalid input syntax for type interval: "1 second 2 seconds"
LINE 1: SELECT '1 second 2 seconds'::interval;
               ^
SELECT '10 milliseconds 20 milliseconds'::interval; -- error
ERROR:  invalid input syntax for type interval: "10 milliseconds 20 milliseconds"
LINE 1: SELECT '10 milliseconds 20 milliseconds'::interval;
               ^
SELECT '5.5 seconds 3 milliseconds'::interval;      -- error
ERROR:  invalid input syntax for type interval: "5.5 seconds 3 milliseconds"
LINE 1: SELECT '5.5 seconds 3 milliseconds'::interval;
               ^
SELECT '1:20:05 5 microseconds'::interval;          -- error
ERROR:  invalid input syntax for type interval: "1:20:05 5 microseconds"
LINE 1: SELECT '1:20:05 5 microseconds'::interval;
               ^
SELECT '1 day 1 day'::interval;                     -- error
ERROR:  invalid input syntax for type interval: "1 day 1 day"
LINE 1: SELECT '1 day 1 day'::interval;
               ^
SELECT interval '1-2';  -- SQL year-month literal
   interval    
---------------
 1 year 2 mons
(1 row)

SELECT interval '999' second;  -- oversize leading field is ok
 interval 
----------
 00:16:39
(1 row)

SELECT interval '999' minute;
 interval 
----------
 16:39:00
(1 row)

SELECT interval '999' hour;
 interval  
-----------
 999:00:00
(1 row)

SELECT interval '999' day;
 interval 
----------
 999 days
(1 row)

SELECT interval '999' month;
    interval     
-----------------
 83 years 3 mons
(1 row)

-- test SQL-spec syntaxes for restricted field sets
SELECT interval '1' year;
 interval 
----------
 1 year
(1 row)

SELECT interval '2' month;
 interval 
----------
 2 mons
(1 row)

SELECT interval '3' day;
 interval 
----------
 3 days
(1 row)

SELECT interval '4' hour;
 interval 
----------
 04:00:00
(1 row)

SELECT interval '5' minute;
 interval 
----------
 00:05:00
(1 row)

SELECT interval '6' second;
 interval 
----------
 00:00:06
(1 row)

SELECT interval '1' year to month;
 interval 
----------
 1 mon
(1 row)

SELECT interval '1-2' year to month;
   interval    
---------------
 1 year 2 mons
(1 row)

SELECT interval '1 2' day to hour;
    interval    
----------------
 1 day 02:00:00
(1 row)

SELECT interval '1 2:03' day to hour;
    interval    
----------------
 1 day 02:00:00
(1 row)

SELECT interval '1 2:03:04' day to hour;
    interval    
----------------
 1 day 02:00:00
(1 row)

SELECT interval '1 2' day to minute;
ERROR:  invalid input syntax for type interval: "1 2"
LINE 1: SELECT interval '1 2' day to minute;
                        ^
SELECT interval '1 2:03' day to minute;
    interval    
----------------
 1 day 02:03:00
(1 row)

SELECT interval '1 2:03:04' day to minute;
    interval    
----------------
 1 day 02:03:00
(1 row)

SELECT interval '1 2' day to second;
ERROR:  invalid input syntax for type interval: "1 2"
LINE 1: SELECT interval '1 2' day to second;
                        ^
SELECT interval '1 2:03' day to second;
    interval    
----------------
 1 day 02:03:00
(1 row)

SELECT interval '1 2:03:04' day to second;
    interval    
----------------
 1 day 02:03:04
(1 row)

SELECT interval '1 2' hour to minute;
ERROR:  invalid input syntax for type interval: "1 2"
LINE 1: SELECT interval '1 2' hour to minute;
                        ^
SELECT interval '1 2:03' hour to minute;
    interval    
----------------
 1 day 02:03:00
(1 row)

SELECT interval '1 2:03:04' hour to minute;
    interval    
----------------
 1 day 02:03:00
(1 row)

SELECT interval '1 2' hour to second;
ERROR:  invalid input syntax for type interval: "1 2"
LINE 1: SELECT interval '1 2' hour to second;
                        ^
SELECT interval '1 2:03' hour to second;
    interval    
----------------
 1 day 02:03:00
(1 row)

SELECT interval '1 2:03:04' hour to second;
    interval    
----------------
 1 day 02:03:04
(1 row)

SELECT interval '1 2' minute to second;
ERROR:  invalid input syntax for type interval: "1 2"
LINE 1: SELECT interval '1 2' minute to second;
                        ^
SELECT interval '1 2:03' minute to second;
    interval    
----------------
 1 day 00:02:03
(1 row)

SELECT interval '1 2:03:04' minute to second;
    interval    
----------------
 1 day 02:03:04
(1 row)

SELECT interval '1 +2:03' minute to second;
    interval    
----------------
 1 day 00:02:03
(1 row)

SELECT interval '1 +2:03:04' minute to second;
    interval    
----------------
 1 day 02:03:04
(1 row)

SELECT interval '1 -2:03' minute to second;
    interval     
-----------------
 1 day -00:02:03
(1 row)

SELECT interval '1 -2:03:04' minute to second;
    interval     
-----------------
 1 day -02:03:04
(1 row)

SELECT interval '123 11' day to hour; -- ok
     interval      
-------------------
 123 days 11:00:00
(1 row)

SELECT interval '123 11' day; -- not ok
ERROR:  invalid input syntax for type interval: "123 11"
LINE 1: SELECT interval '123 11' day;
                        ^
SELECT interval '123 11'; -- not ok, too ambiguous
ERROR:  invalid input syntax for type interval: "123 11"
LINE 1: SELECT interval '123 11';
                        ^
SELECT interval '123 2:03 -2:04'; -- not ok, redundant hh:mm fields
ERROR:  invalid input syntax for type interval: "123 2:03 -2:04"
LINE 1: SELECT interval '123 2:03 -2:04';
                        ^
-- test syntaxes for restricted precision
SELECT interval(0) '1 day 01:23:45.6789';
    interval    
----------------
 1 day 01:23:46
(1 row)

SELECT interval(2) '1 day 01:23:45.6789';
     interval      
-------------------
 1 day 01:23:45.68
(1 row)

SELECT interval '12:34.5678' minute to second(2);  -- per SQL spec
  interval   
-------------
 00:12:34.57
(1 row)

SELECT interval '1.234' second;
   interval   
--------------
 00:00:01.234
(1 row)

SELECT interval '1.234' second(2);
  interval   
-------------
 00:00:01.23
(1 row)

SELECT interval '1 2.345' day to second(2);
ERROR:  invalid input syntax for type interval: "1 2.345"
LINE 1: SELECT interval '1 2.345' day to second(2);
                        ^
SELECT interval '1 2:03' day to second(2);
    interval    
----------------
 1 day 02:03:00
(1 row)

SELECT interval '1 2:03.4567' day to second(2);
     interval      
-------------------
 1 day 00:02:03.46
(1 row)

SELECT interval '1 2:03:04.5678' day to second(2);
     interval      
-------------------
 1 day 02:03:04.57
(1 row)

SELECT interval '1 2.345' hour to second(2);
ERROR:  invalid input syntax for type interval: "1 2.345"
LINE 1: SELECT interval '1 2.345' hour to second(2);
                        ^
SELECT interval '1 2:03.45678' hour to second(2);
     interval      
-------------------
 1 day 00:02:03.46
(1 row)

SELECT interval '1 2:03:04.5678' hour to second(2);
     interval      
-------------------
 1 day 02:03:04.57
(1 row)

SELECT interval '1 2.3456' minute to second(2);
ERROR:  invalid input syntax for type interval: "1 2.3456"
LINE 1: SELECT interval '1 2.3456' minute to second(2);
                        ^
SELECT interval '1 2:03.5678' minute to second(2);
     interval      
-------------------
 1 day 00:02:03.57
(1 row)

SELECT interval '1 2:03:04.5678' minute to second(2);
     interval      
-------------------
 1 day 02:03:04.57
(1 row)

-- test casting to restricted precision (bug #14479)
SELECT f1, f1::INTERVAL DAY TO MINUTE AS "minutes",
  (f1 + INTERVAL '1 month')::INTERVAL MONTH::INTERVAL YEAR AS "years"
  FROM interval_tbl;
       f1        |     minutes     |  years   
-----------------+-----------------+----------
 00:01:00        | 00:01:00        | 00:00:00
 05:00:00        | 05:00:00        | 00:00:00
 10 days         | 10 days         | 00:00:00
 34 years        | 34 years        | 34 years
 3 mons          | 3 mons          | 00:00:00
 -00:00:14       | 00:00:00        | 00:00:00
 1 day 02:03:04  | 1 day 02:03:00  | 00:00:00
 6 years         | 6 years         | 6 years
 5 mons          | 5 mons          | 00:00:00
 5 mons 12:00:00 | 5 mons 12:00:00 | 00:00:00
(10 rows)

-- test inputting and outputting SQL standard interval literals
SET IntervalStyle TO sql_standard;
SELECT  interval '0'                       AS "zero",
        interval '1-2' year to month       AS "year-month",
        interval '1 2:03:04' day to second AS "day-time",
        - interval '1-2'                   AS "negative year-month",
        - interval '1 2:03:04'             AS "negative day-time";
 zero | year-month | day-time  | negative year-month | negative day-time 
------+------------+-----------+---------------------+-------------------
 0    | 1-2        | 1 2:03:04 | -1-2                | -1 2:03:04
(1 row)

-- test input of some not-quite-standard interval values in the sql style
SET IntervalStyle TO postgres;
SELECT  interval '+1 -1:00:00',
        interval '-1 +1:00:00',
        interval '+1-2 -3 +4:05:06.789',
        interval '-1-2 +3 -4:05:06.789';
    interval     |     interval      |              interval               |                interval                
-----------------+-------------------+-------------------------------------+----------------------------------------
 1 day -01:00:00 | -1 days +01:00:00 | 1 year 2 mons -3 days +04:05:06.789 | -1 years -2 mons +3 days -04:05:06.789
(1 row)

-- cases that trigger sign-matching rules in the sql style
SELECT  interval '-23 hours 45 min 12.34 sec',
        interval '-1 day 23 hours 45 min 12.34 sec',
        interval '-1 year 2 months 1 day 23 hours 45 min 12.34 sec',
        interval '-1 year 2 months 1 day 23 hours 45 min +12.34 sec';
   interval   |       interval       |          interval           |          interval           
--------------+----------------------+-----------------------------+-----------------------------
 -22:14:47.66 | -1 days +23:45:12.34 | -10 mons +1 day 23:45:12.34 | -10 mons +1 day 23:45:12.34
(1 row)

-- test output of couple non-standard interval values in the sql style
SET IntervalStyle TO sql_standard;
SELECT  interval '1 day -1 hours',
        interval '-1 days +1 hours',
        interval '1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds',
        - interval '1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds';
     interval     |     interval     |       interval       |       ?column?       
------------------+------------------+----------------------+----------------------
 +0-0 +1 -1:00:00 | +0-0 -1 +1:00:00 | +1-2 -3 +4:05:06.789 | -1-2 +3 -4:05:06.789
(1 row)

-- cases that trigger sign-matching rules in the sql style
SELECT  interval '-23 hours 45 min 12.34 sec',
        interval '-1 day 23 hours 45 min 12.34 sec',
        interval '-1 year 2 months 1 day 23 hours 45 min 12.34 sec',
        interval '-1 year 2 months 1 day 23 hours 45 min +12.34 sec';
   interval   |    interval    |       interval       |       interval        
--------------+----------------+----------------------+-----------------------
 -23:45:12.34 | -1 23:45:12.34 | -1-2 -1 -23:45:12.34 | -0-10 +1 +23:45:12.34
(1 row)

-- edge case for sign-matching rules
SELECT  interval '';  -- error
ERROR:  invalid input syntax for type interval: ""
LINE 1: SELECT  interval '';
                         ^
-- test outputting iso8601 intervals
SET IntervalStyle to iso_8601;
select  interval '0'                                AS "zero",
        interval '1-2'                              AS "a year 2 months",
        interval '1 2:03:04'                        AS "a bit over a day",
        interval '2:03:04.45679'                    AS "a bit over 2 hours",
        (interval '1-2' + interval '3 4:05:06.7')   AS "all fields",
        (interval '1-2' - interval '3 4:05:06.7')   AS "mixed sign",
        (- interval '1-2' + interval '3 4:05:06.7') AS "negative";
 zero | a year 2 months | a bit over a day | a bit over 2 hours |    all fields    |      mixed sign      |      negative      
------+-----------------+------------------+--------------------+------------------+----------------------+--------------------
 PT0S | P1Y2M           | P1DT2H3M4S       | PT2H3M4.45679S     | P1Y2M3DT4H5M6.7S | P1Y2M-3DT-4H-5M-6.7S | P-1Y-2M3DT4H5M6.7S
(1 row)

-- test inputting ISO 8601 4.4.2.1 "Format With Time Unit Designators"
SET IntervalStyle to sql_standard;
select  interval 'P0Y'                    AS "zero",
        interval 'P1Y2M'                  AS "a year 2 months",
        interval 'P1W'                    AS "a week",
        interval 'P1DT2H3M4S'             AS "a bit over a day",
        interval 'P1Y2M3DT4H5M6.7S'       AS "all fields",
        interval 'P-1Y-2M-3DT-4H-5M-6.7S' AS "negative",
        interval 'PT-0.1S'                AS "fractional second";
 zero | a year 2 months |  a week   | a bit over a day |     all fields     |      negative      | fractional second 
------+-----------------+-----------+------------------+--------------------+--------------------+-------------------
 0    | 1-2             | 7 0:00:00 | 1 2:03:04        | +1-2 +3 +4:05:06.7 | -1-2 -3 -4:05:06.7 | -0:00:00.1
(1 row)

-- test inputting ISO 8601 4.4.2.2 "Alternative Format"
SET IntervalStyle to postgres;
select  interval 'P00021015T103020'       AS "ISO8601 Basic Format",
        interval 'P0002-10-15T10:30:20'   AS "ISO8601 Extended Format";
       ISO8601 Basic Format       |     ISO8601 Extended Format      
----------------------------------+----------------------------------
 2 years 10 mons 15 days 10:30:20 | 2 years 10 mons 15 days 10:30:20
(1 row)

-- Make sure optional ISO8601 alternative format fields are optional.
select  interval 'P0002'                  AS "year only",
        interval 'P0002-10'               AS "year month",
        interval 'P0002-10-15'            AS "year month day",
        interval 'P0002T1S'               AS "year only plus time",
        interval 'P0002-10T1S'            AS "year month plus time",
        interval 'P0002-10-15T1S'         AS "year month day plus time",
        interval 'PT10'                   AS "hour only",
        interval 'PT10:30'                AS "hour minute";
 year only |   year month    |     year month day      | year only plus time |   year month plus time   |     year month day plus time     | hour only | hour minute 
-----------+-----------------+-------------------------+---------------------+--------------------------+----------------------------------+-----------+-------------
 2 years   | 2 years 10 mons | 2 years 10 mons 15 days | 2 years 00:00:01    | 2 years 10 mons 00:00:01 | 2 years 10 mons 15 days 00:00:01 | 10:00:00  | 10:30:00
(1 row)

-- Check handling of fractional fields in ISO8601 format.
select interval 'P1Y0M3DT4H5M6S';
        interval        
------------------------
 1 year 3 days 04:05:06
(1 row)

select interval 'P1.0Y0M3DT4H5M6S';
        interval        
------------------------
 1 year 3 days 04:05:06
(1 row)

select interval 'P1.1Y0M3DT4H5M6S';
           interval           
------------------------------
 1 year 1 mon 3 days 04:05:06
(1 row)

select interval 'P1.Y0M3DT4H5M6S';
        interval        
------------------------
 1 year 3 days 04:05:06
(1 row)

select interval 'P.1Y0M3DT4H5M6S';
       interval        
-----------------------
 1 mon 3 days 04:05:06
(1 row)

select interval 'P10.5e4Y';  -- not per spec, but we've historically taken it
   interval   
--------------
 105000 years
(1 row)

select interval 'P.Y0M3DT4H5M6S';  -- error
ERROR:  invalid input syntax for type interval: "P.Y0M3DT4H5M6S"
LINE 1: select interval 'P.Y0M3DT4H5M6S';
                        ^
-- test a couple rounding cases that changed since 8.3 w/ HAVE_INT64_TIMESTAMP.
SET IntervalStyle to postgres_verbose;
select interval '-10 mons -3 days +03:55:06.70';
                     interval                     
--------------------------------------------------
 @ 10 mons 3 days -3 hours -55 mins -6.7 secs ago
(1 row)

select interval '1 year 2 mons 3 days 04:05:06.699999';
                      interval                       
-----------------------------------------------------
 @ 1 year 2 mons 3 days 4 hours 5 mins 6.699999 secs
(1 row)

select interval '0:0:0.7', interval '@ 0.70 secs', interval '0.7 seconds';
  interval  |  interval  |  interval  
------------+------------+------------
 @ 0.7 secs | @ 0.7 secs | @ 0.7 secs
(1 row)

-- test time fields using entire 64 bit microseconds range
select interval '2562047788.01521550194 hours';
             interval              
-----------------------------------
 @ 2562047788 hours 54.775807 secs
(1 row)

select interval '-2562047788.01521550222 hours';
               interval                
---------------------------------------
 @ 2562047788 hours 54.775808 secs ago
(1 row)

select interval '153722867280.912930117 minutes';
             interval              
-----------------------------------
 @ 2562047788 hours 54.775807 secs
(1 row)

select interval '-153722867280.912930133 minutes';
               interval                
---------------------------------------
 @ 2562047788 hours 54.775808 secs ago
(1 row)

select interval '9223372036854.775807 seconds';
             interval              
-----------------------------------
 @ 2562047788 hours 54.775807 secs
(1 row)

select interval '-9223372036854.775808 seconds';
               interval                
---------------------------------------
 @ 2562047788 hours 54.775808 secs ago
(1 row)

select interval '9223372036854775.807 milliseconds';
             interval              
-----------------------------------
 @ 2562047788 hours 54.775807 secs
(1 row)

select interval '-9223372036854775.808 milliseconds';
               interval                
---------------------------------------
 @ 2562047788 hours 54.775808 secs ago
(1 row)

select interval '9223372036854775807 microseconds';
             interval              
-----------------------------------
 @ 2562047788 hours 54.775807 secs
(1 row)

select interval '-9223372036854775808 microseconds';
               interval                
---------------------------------------
 @ 2562047788 hours 54.775808 secs ago
(1 row)

select interval 'PT2562047788H54.775807S';
             interval              
-----------------------------------
 @ 2562047788 hours 54.775807 secs
(1 row)

select interval 'PT-2562047788H-54.775808S';
               interval                
---------------------------------------
 @ 2562047788 hours 54.775808 secs ago
(1 row)

select interval 'PT2562047788:00:54.775807';
             interval              
-----------------------------------
 @ 2562047788 hours 54.775807 secs
(1 row)

select interval 'PT2562047788.0152155019444';
             interval              
-----------------------------------
 @ 2562047788 hours 54.775429 secs
(1 row)

select interval 'PT-2562047788.0152155022222';
               interval                
---------------------------------------
 @ 2562047788 hours 54.775429 secs ago
(1 row)

-- overflow each date/time field
select interval '2147483648 years';
ERROR:  interval field value out of range: "2147483648 years"
LINE 1: select interval '2147483648 years';
                        ^
select interval '-2147483649 years';
ERROR:  interval field value out of range: "-2147483649 years"
LINE 1: select interval '-2147483649 years';
                        ^
select interval '2147483648 months';
ERROR:  interval field value out of range: "2147483648 months"
LINE 1: select interval '2147483648 months';
                        ^
select interval '-2147483649 months';
ERROR:  interval field value out of range: "-2147483649 months"
LINE 1: select interval '-2147483649 months';
                        ^
select interval '2147483648 days';
ERROR:  interval field value out of range: "2147483648 days"
LINE 1: select interval '2147483648 days';
                        ^
select interval '-2147483649 days';
ERROR:  interval field value out of range: "-2147483649 days"
LINE 1: select interval '-2147483649 days';
                        ^
select interval '2562047789 hours';
ERROR:  interval field value out of range: "2562047789 hours"
LINE 1: select interval '2562047789 hours';
                        ^
select interval '-2562047789 hours';
ERROR:  interval field value out of range: "-2562047789 hours"
LINE 1: select interval '-2562047789 hours';
                        ^
select interval '153722867281 minutes';
ERROR:  interval field value out of range: "153722867281 minutes"
LINE 1: select interval '153722867281 minutes';
                        ^
select interval '-153722867281 minutes';
ERROR:  interval field value out of range: "-153722867281 minutes"
LINE 1: select interval '-153722867281 minutes';
                        ^
select interval '9223372036855 seconds';
ERROR:  interval field value out of range: "9223372036855 seconds"
LINE 1: select interval '9223372036855 seconds';
                        ^
select interval '-9223372036855 seconds';
ERROR:  interval field value out of range: "-9223372036855 seconds"
LINE 1: select interval '-9223372036855 seconds';
                        ^
select interval '9223372036854777 millisecond';
ERROR:  interval field value out of range: "9223372036854777 millisecond"
LINE 1: select interval '9223372036854777 millisecond';
                        ^
select interval '-9223372036854777 millisecond';
ERROR:  interval field value out of range: "-9223372036854777 millisecond"
LINE 1: select interval '-9223372036854777 millisecond';
                        ^
select interval '9223372036854775808 microsecond';
ERROR:  interval field value out of range: "9223372036854775808 microsecond"
LINE 1: select interval '9223372036854775808 microsecond';
                        ^
select interval '-9223372036854775809 microsecond';
ERROR:  interval field value out of range: "-9223372036854775809 microsecond"
LINE 1: select interval '-9223372036854775809 microsecond';
                        ^
select interval 'P2147483648';
ERROR:  interval field value out of range: "P2147483648"
LINE 1: select interval 'P2147483648';
                        ^
select interval 'P-2147483649';
ERROR:  interval field value out of range: "P-2147483649"
LINE 1: select interval 'P-2147483649';
                        ^
select interval 'P1-2147483647-2147483647';
ERROR:  interval out of range
LINE 1: select interval 'P1-2147483647-2147483647';
                        ^
select interval 'PT2562047789';
ERROR:  interval field value out of range: "PT2562047789"
LINE 1: select interval 'PT2562047789';
                        ^
select interval 'PT-2562047789';
ERROR:  interval field value out of range: "PT-2562047789"
LINE 1: select interval 'PT-2562047789';
                        ^
-- overflow with date/time unit aliases
select interval '2147483647 weeks';
ERROR:  interval field value out of range: "2147483647 weeks"
LINE 1: select interval '2147483647 weeks';
                        ^
select interval '-2147483648 weeks';
ERROR:  interval field value out of range: "-2147483648 weeks"
LINE 1: select interval '-2147483648 weeks';
                        ^
select interval '2147483647 decades';
ERROR:  interval field value out of range: "2147483647 decades"
LINE 1: select interval '2147483647 decades';
                        ^
select interval '-2147483648 decades';
ERROR:  interval field value out of range: "-2147483648 decades"
LINE 1: select interval '-2147483648 decades';
                        ^
select interval '2147483647 centuries';
ERROR:  interval field value out of range: "2147483647 centuries"
LINE 1: select interval '2147483647 centuries';
                        ^
select interval '-2147483648 centuries';
ERROR:  interval field value out of range: "-2147483648 centuries"
LINE 1: select interval '-2147483648 centuries';
                        ^
select interval '2147483647 millennium';
ERROR:  interval field value out of range: "2147483647 millennium"
LINE 1: select interval '2147483647 millennium';
                        ^
select interval '-2147483648 millennium';
ERROR:  interval field value out of range: "-2147483648 millennium"
LINE 1: select interval '-2147483648 millennium';
                        ^
select interval '1 week 2147483647 days';
ERROR:  interval field value out of range: "1 week 2147483647 days"
LINE 1: select interval '1 week 2147483647 days';
                        ^
select interval '-1 week -2147483648 days';
ERROR:  interval field value out of range: "-1 week -2147483648 days"
LINE 1: select interval '-1 week -2147483648 days';
                        ^
select interval '2147483647 days 1 week';
ERROR:  interval field value out of range: "2147483647 days 1 week"
LINE 1: select interval '2147483647 days 1 week';
                        ^
select interval '-2147483648 days -1 week';
ERROR:  interval field value out of range: "-2147483648 days -1 week"
LINE 1: select interval '-2147483648 days -1 week';
                        ^
select interval 'P1W2147483647D';
ERROR:  interval field value out of range: "P1W2147483647D"
LINE 1: select interval 'P1W2147483647D';
                        ^
select interval 'P-1W-2147483648D';
ERROR:  interval field value out of range: "P-1W-2147483648D"
LINE 1: select interval 'P-1W-2147483648D';
                        ^
select interval 'P2147483647D1W';
ERROR:  interval field value out of range: "P2147483647D1W"
LINE 1: select interval 'P2147483647D1W';
                        ^
select interval 'P-2147483648D-1W';
ERROR:  interval field value out of range: "P-2147483648D-1W"
LINE 1: select interval 'P-2147483648D-1W';
                        ^
select interval '1 decade 2147483647 years';
ERROR:  interval field value out of range: "1 decade 2147483647 years"
LINE 1: select interval '1 decade 2147483647 years';
                        ^
select interval '1 century 2147483647 years';
ERROR:  interval field value out of range: "1 century 2147483647 years"
LINE 1: select interval '1 century 2147483647 years';
                        ^
select interval '1 millennium 2147483647 years';
ERROR:  interval field value out of range: "1 millennium 2147483647 years"
LINE 1: select interval '1 millennium 2147483647 years';
                        ^
select interval '-1 decade -2147483648 years';
ERROR:  interval field value out of range: "-1 decade -2147483648 years"
LINE 1: select interval '-1 decade -2147483648 years';
                        ^
select interval '-1 century -2147483648 years';
ERROR:  interval field value out of range: "-1 century -2147483648 years"
LINE 1: select interval '-1 century -2147483648 years';
                        ^
select interval '-1 millennium -2147483648 years';
ERROR:  interval field value out of range: "-1 millennium -2147483648 years"
LINE 1: select interval '-1 millennium -2147483648 years';
                        ^
select interval '2147483647 years 1 decade';
ERROR:  interval field value out of range: "2147483647 years 1 decade"
LINE 1: select interval '2147483647 years 1 decade';
                        ^
select interval '2147483647 years 1 century';
ERROR:  interval field value out of range: "2147483647 years 1 century"
LINE 1: select interval '2147483647 years 1 century';
                        ^
select interval '2147483647 years 1 millennium';
ERROR:  interval field value out of range: "2147483647 years 1 millennium"
LINE 1: select interval '2147483647 years 1 millennium';
                        ^
select interval '-2147483648 years -1 decade';
ERROR:  interval field value out of range: "-2147483648 years -1 decade"
LINE 1: select interval '-2147483648 years -1 decade';
                        ^
select interval '-2147483648 years -1 century';
ERROR:  interval field value out of range: "-2147483648 years -1 century"
LINE 1: select interval '-2147483648 years -1 century';
                        ^
select interval '-2147483648 years -1 millennium';
ERROR:  interval field value out of range: "-2147483648 years -1 millennium"
LINE 1: select interval '-2147483648 years -1 millennium';
                        ^
-- overflowing with fractional fields - postgres format
select interval '0.1 millennium 2147483647 months';
ERROR:  interval field value out of range: "0.1 millennium 2147483647 months"
LINE 1: select interval '0.1 millennium 2147483647 months';
                        ^
select interval '0.1 centuries 2147483647 months';
ERROR:  interval field value out of range: "0.1 centuries 2147483647 months"
LINE 1: select interval '0.1 centuries 2147483647 months';
                        ^
select interval '0.1 decades 2147483647 months';
ERROR:  interval field value out of range: "0.1 decades 2147483647 months"
LINE 1: select interval '0.1 decades 2147483647 months';
                        ^
select interval '0.1 yrs 2147483647 months';
ERROR:  interval field value out of range: "0.1 yrs 2147483647 months"
LINE 1: select interval '0.1 yrs 2147483647 months';
                        ^
select interval '-0.1 millennium -2147483648 months';
ERROR:  interval field value out of range: "-0.1 millennium -2147483648 months"
LINE 1: select interval '-0.1 millennium -2147483648 months';
                        ^
select interval '-0.1 centuries -2147483648 months';
ERROR:  interval field value out of range: "-0.1 centuries -2147483648 months"
LINE 1: select interval '-0.1 centuries -2147483648 months';
                        ^
select interval '-0.1 decades -2147483648 months';
ERROR:  interval field value out of range: "-0.1 decades -2147483648 months"
LINE 1: select interval '-0.1 decades -2147483648 months';
                        ^
select interval '-0.1 yrs -2147483648 months';
ERROR:  interval field value out of range: "-0.1 yrs -2147483648 months"
LINE 1: select interval '-0.1 yrs -2147483648 months';
                        ^
select interval '2147483647 months 0.1 millennium';
ERROR:  interval field value out of range: "2147483647 months 0.1 millennium"
LINE 1: select interval '2147483647 months 0.1 millennium';
                        ^
select interval '2147483647 months 0.1 centuries';
ERROR:  interval field value out of range: "2147483647 months 0.1 centuries"
LINE 1: select interval '2147483647 months 0.1 centuries';
                        ^
select interval '2147483647 months 0.1 decades';
ERROR:  interval field value out of range: "2147483647 months 0.1 decades"
LINE 1: select interval '2147483647 months 0.1 decades';
                        ^
select interval '2147483647 months 0.1 yrs';
ERROR:  interval field value out of range: "2147483647 months 0.1 yrs"
LINE 1: select interval '2147483647 months 0.1 yrs';
                        ^
select interval '-2147483648 months -0.1 millennium';
ERROR:  interval field value out of range: "-2147483648 months -0.1 millennium"
LINE 1: select interval '-2147483648 months -0.1 millennium';
                        ^
select interval '-2147483648 months -0.1 centuries';
ERROR:  interval field value out of range: "-2147483648 months -0.1 centuries"
LINE 1: select interval '-2147483648 months -0.1 centuries';
                        ^
select interval '-2147483648 months -0.1 decades';
ERROR:  interval field value out of range: "-2147483648 months -0.1 decades"
LINE 1: select interval '-2147483648 months -0.1 decades';
                        ^
select interval '-2147483648 months -0.1 yrs';
ERROR:  interval field value out of range: "-2147483648 months -0.1 yrs"
LINE 1: select interval '-2147483648 months -0.1 yrs';
                        ^
select interval '0.1 months 2147483647 days';
ERROR:  interval field value out of range: "0.1 months 2147483647 days"
LINE 1: select interval '0.1 months 2147483647 days';
                        ^
select interval '-0.1 months -2147483648 days';
ERROR:  interval field value out of range: "-0.1 months -2147483648 days"
LINE 1: select interval '-0.1 months -2147483648 days';
                        ^
select interval '2147483647 days 0.1 months';
ERROR:  interval field value out of range: "2147483647 days 0.1 months"
LINE 1: select interval '2147483647 days 0.1 months';
                        ^
select interval '-2147483648 days -0.1 months';
ERROR:  interval field value out of range: "-2147483648 days -0.1 months"
LINE 1: select interval '-2147483648 days -0.1 months';
                        ^
select interval '0.5 weeks 2147483647 days';
ERROR:  interval field value out of range: "0.5 weeks 2147483647 days"
LINE 1: select interval '0.5 weeks 2147483647 days';
                        ^
select interval '-0.5 weeks -2147483648 days';
ERROR:  interval field value out of range: "-0.5 weeks -2147483648 days"
LINE 1: select interval '-0.5 weeks -2147483648 days';
                        ^
select interval '2147483647 days 0.5 weeks';
ERROR:  interval field value out of range: "2147483647 days 0.5 weeks"
LINE 1: select interval '2147483647 days 0.5 weeks';
                        ^
select interval '-2147483648 days -0.5 weeks';
ERROR:  interval field value out of range: "-2147483648 days -0.5 weeks"
LINE 1: select interval '-2147483648 days -0.5 weeks';
                        ^
select interval '0.01 months 9223372036854775807 microseconds';
ERROR:  interval field value out of range: "0.01 months 9223372036854775807 microseconds"
LINE 1: select interval '0.01 months 9223372036854775807 microsecond...
                        ^
select interval '-0.01 months -9223372036854775808 microseconds';
ERROR:  interval field value out of range: "-0.01 months -9223372036854775808 microseconds"
LINE 1: select interval '-0.01 months -9223372036854775808 microseco...
                        ^
select interval '9223372036854775807 microseconds 0.01 months';
ERROR:  interval field value out of range: "9223372036854775807 microseconds 0.01 months"
LINE 1: select interval '9223372036854775807 microseconds 0.01 month...
                        ^
select interval '-9223372036854775808 microseconds -0.01 months';
ERROR:  interval field value out of range: "-9223372036854775808 microseconds -0.01 months"
LINE 1: select interval '-9223372036854775808 microseconds -0.01 mon...
                        ^
select interval '0.1 weeks 9223372036854775807 microseconds';
ERROR:  interval field value out of range: "0.1 weeks 9223372036854775807 microseconds"
LINE 1: select interval '0.1 weeks 9223372036854775807 microseconds'...
                        ^
select interval '-0.1 weeks -9223372036854775808 microseconds';
ERROR:  interval field value out of range: "-0.1 weeks -9223372036854775808 microseconds"
LINE 1: select interval '-0.1 weeks -9223372036854775808 microsecond...
                        ^
select interval '9223372036854775807 microseconds 0.1 weeks';
ERROR:  interval field value out of range: "9223372036854775807 microseconds 0.1 weeks"
LINE 1: select interval '9223372036854775807 microseconds 0.1 weeks'...
                        ^
select interval '-9223372036854775808 microseconds -0.1 weeks';
ERROR:  interval field value out of range: "-9223372036854775808 microseconds -0.1 weeks"
LINE 1: select interval '-9223372036854775808 microseconds -0.1 week...
                        ^
select interval '0.1 days 9223372036854775807 microseconds';
ERROR:  interval field value out of range: "0.1 days 9223372036854775807 microseconds"
LINE 1: select interval '0.1 days 9223372036854775807 microseconds';
                        ^
select interval '-0.1 days -9223372036854775808 microseconds';
ERROR:  interval field value out of range: "-0.1 days -9223372036854775808 microseconds"
LINE 1: select interval '-0.1 days -9223372036854775808 microseconds...
                        ^
select interval '9223372036854775807 microseconds 0.1 days';
ERROR:  interval field value out of range: "9223372036854775807 microseconds 0.1 days"
LINE 1: select interval '9223372036854775807 microseconds 0.1 days';
                        ^
select interval '-9223372036854775808 microseconds -0.1 days';
ERROR:  interval field value out of range: "-9223372036854775808 microseconds -0.1 days"
LINE 1: select interval '-9223372036854775808 microseconds -0.1 days...
                        ^
-- overflowing with fractional fields - ISO8601 format
select interval 'P0.1Y2147483647M';
ERROR:  interval field value out of range: "P0.1Y2147483647M"
LINE 1: select interval 'P0.1Y2147483647M';
                        ^
select interval 'P-0.1Y-2147483648M';
ERROR:  interval field value out of range: "P-0.1Y-2147483648M"
LINE 1: select interval 'P-0.1Y-2147483648M';
                        ^
select interval 'P2147483647M0.1Y';
ERROR:  interval field value out of range: "P2147483647M0.1Y"
LINE 1: select interval 'P2147483647M0.1Y';
                        ^
select interval 'P-2147483648M-0.1Y';
ERROR:  interval field value out of range: "P-2147483648M-0.1Y"
LINE 1: select interval 'P-2147483648M-0.1Y';
                        ^
select interval 'P0.1M2147483647D';
ERROR:  interval field value out of range: "P0.1M2147483647D"
LINE 1: select interval 'P0.1M2147483647D';
                        ^
select interval 'P-0.1M-2147483648D';
ERROR:  interval field value out of range: "P-0.1M-2147483648D"
LINE 1: select interval 'P-0.1M-2147483648D';
                        ^
select interval 'P2147483647D0.1M';
ERROR:  interval field value out of range: "P2147483647D0.1M"
LINE 1: select interval 'P2147483647D0.1M';
                        ^
select interval 'P-2147483648D-0.1M';
ERROR:  interval field value out of range: "P-2147483648D-0.1M"
LINE 1: select interval 'P-2147483648D-0.1M';
                        ^
select interval 'P0.5W2147483647D';
ERROR:  interval field value out of range: "P0.5W2147483647D"
LINE 1: select interval 'P0.5W2147483647D';
                        ^
select interval 'P-0.5W-2147483648D';
ERROR:  interval field value out of range: "P-0.5W-2147483648D"
LINE 1: select interval 'P-0.5W-2147483648D';
                        ^
select interval 'P2147483647D0.5W';
ERROR:  interval field value out of range: "P2147483647D0.5W"
LINE 1: select interval 'P2147483647D0.5W';
                        ^
select interval 'P-2147483648D-0.5W';
ERROR:  interval field value out of range: "P-2147483648D-0.5W"
LINE 1: select interval 'P-2147483648D-0.5W';
                        ^
select interval 'P0.01MT2562047788H54.775807S';
ERROR:  interval field value out of range: "P0.01MT2562047788H54.775807S"
LINE 1: select interval 'P0.01MT2562047788H54.775807S';
                        ^
select interval 'P-0.01MT-2562047788H-54.775808S';
ERROR:  interval field value out of range: "P-0.01MT-2562047788H-54.775808S"
LINE 1: select interval 'P-0.01MT-2562047788H-54.775808S';
                        ^
select interval 'P0.1DT2562047788H54.775807S';
ERROR:  interval field value out of range: "P0.1DT2562047788H54.775807S"
LINE 1: select interval 'P0.1DT2562047788H54.775807S';
                        ^
select interval 'P-0.1DT-2562047788H-54.775808S';
ERROR:  interval field value out of range: "P-0.1DT-2562047788H-54.775808S"
LINE 1: select interval 'P-0.1DT-2562047788H-54.775808S';
                        ^
select interval 'PT2562047788.1H54.775807S';
ERROR:  interval field value out of range: "PT2562047788.1H54.775807S"
LINE 1: select interval 'PT2562047788.1H54.775807S';
                        ^
select interval 'PT-2562047788.1H-54.775808S';
ERROR:  interval field value out of range: "PT-2562047788.1H-54.775808S"
LINE 1: select interval 'PT-2562047788.1H-54.775808S';
                        ^
select interval 'PT2562047788H0.1M54.775807S';
ERROR:  interval field value out of range: "PT2562047788H0.1M54.775807S"
LINE 1: select interval 'PT2562047788H0.1M54.775807S';
                        ^
select interval 'PT-2562047788H-0.1M-54.775808S';
ERROR:  interval field value out of range: "PT-2562047788H-0.1M-54.775808S"
LINE 1: select interval 'PT-2562047788H-0.1M-54.775808S';
                        ^
-- overflowing with fractional fields - ISO8601 alternative format
select interval 'P0.1-2147483647-00';
ERROR:  interval field value out of range: "P0.1-2147483647-00"
LINE 1: select interval 'P0.1-2147483647-00';
                        ^
select interval 'P00-0.1-2147483647';
ERROR:  interval field value out of range: "P00-0.1-2147483647"
LINE 1: select interval 'P00-0.1-2147483647';
                        ^
select interval 'P00-0.01-00T2562047788:00:54.775807';
ERROR:  interval field value out of range: "P00-0.01-00T2562047788:00:54.775807"
LINE 1: select interval 'P00-0.01-00T2562047788:00:54.775807';
                        ^
select interval 'P00-00-0.1T2562047788:00:54.775807';
ERROR:  interval field value out of range: "P00-00-0.1T2562047788:00:54.775807"
LINE 1: select interval 'P00-00-0.1T2562047788:00:54.775807';
                        ^
select interval 'PT2562047788.1:00:54.775807';
ERROR:  interval field value out of range: "PT2562047788.1:00:54.775807"
LINE 1: select interval 'PT2562047788.1:00:54.775807';
                        ^
select interval 'PT2562047788:01.:54.775807';
ERROR:  interval field value out of range: "PT2562047788:01.:54.775807"
LINE 1: select interval 'PT2562047788:01.:54.775807';
                        ^
-- overflowing with fractional fields - SQL standard format
select interval '0.1 2562047788:0:54.775807';
ERROR:  interval field value out of range: "0.1 2562047788:0:54.775807"
LINE 1: select interval '0.1 2562047788:0:54.775807';
                        ^
select interval '0.1 2562047788:0:54.775808 ago';
ERROR:  interval field value out of range: "0.1 2562047788:0:54.775808 ago"
LINE 1: select interval '0.1 2562047788:0:54.775808 ago';
                        ^
select interval '2562047788.1:0:54.775807';
ERROR:  interval field value out of range: "2562047788.1:0:54.775807"
LINE 1: select interval '2562047788.1:0:54.775807';
                        ^
select interval '2562047788.1:0:54.775808 ago';
ERROR:  interval field value out of range: "2562047788.1:0:54.775808 ago"
LINE 1: select interval '2562047788.1:0:54.775808 ago';
                        ^
select interval '2562047788:0.1:54.775807';
ERROR:  invalid input syntax for type interval: "2562047788:0.1:54.775807"
LINE 1: select interval '2562047788:0.1:54.775807';
                        ^
select interval '2562047788:0.1:54.775808 ago';
ERROR:  invalid input syntax for type interval: "2562047788:0.1:54.775808 ago"
LINE 1: select interval '2562047788:0.1:54.775808 ago';
                        ^
-- overflowing using AGO with INT_MIN
select interval '-2147483648 months ago';
ERROR:  interval field value out of range: "-2147483648 months ago"
LINE 1: select interval '-2147483648 months ago';
                        ^
select interval '-2147483648 days ago';
ERROR:  interval field value out of range: "-2147483648 days ago"
LINE 1: select interval '-2147483648 days ago';
                        ^
select interval '-9223372036854775808 microseconds ago';
ERROR:  interval field value out of range: "-9223372036854775808 microseconds ago"
LINE 1: select interval '-9223372036854775808 microseconds ago';
                        ^
select interval '-2147483648 months -2147483648 days -9223372036854775808 microseconds ago';
ERROR:  interval field value out of range: "-2147483648 months -2147483648 days -9223372036854775808 microseconds ago"
LINE 1: select interval '-2147483648 months -2147483648 days -922337...
                        ^
-- test that INT_MIN number is formatted properly
SET IntervalStyle to postgres;
select interval '-2147483648 months -2147483648 days -9223372036854775808 us';
                              interval                              
--------------------------------------------------------------------
 -178956970 years -8 mons -2147483648 days -2562047788:00:54.775808
(1 row)

SET IntervalStyle to sql_standard;
select interval '-2147483648 months -2147483648 days -9223372036854775808 us';
                     interval                      
---------------------------------------------------
 -178956970-8 -2147483648 -2562047788:00:54.775808
(1 row)

SET IntervalStyle to iso_8601;
select interval '-2147483648 months -2147483648 days -9223372036854775808 us';
                      interval                       
-----------------------------------------------------
 P-178956970Y-8M-2147483648DT-2562047788H-54.775808S
(1 row)

SET IntervalStyle to postgres_verbose;
select interval '-2147483648 months -2147483648 days -9223372036854775808 us';
                                   interval                                   
------------------------------------------------------------------------------
 @ 178956970 years 8 mons 2147483648 days 2562047788 hours 54.775808 secs ago
(1 row)

-- check that '30 days' equals '1 month' according to the hash function
select '30 days'::interval = '1 month'::interval as t;
 t 
---
 t
(1 row)

select interval_hash('30 days'::interval) = interval_hash('1 month'::interval) as t;
 t 
---
 t
(1 row)

-- numeric constructor
select make_interval(years := 2);
 make_interval 
---------------
 @ 2 years
(1 row)

select make_interval(years := 1, months := 6);
  make_interval  
-----------------
 @ 1 year 6 mons
(1 row)

select make_interval(years := 1, months := -1, weeks := 5, days := -7, hours := 25, mins := -180);
       make_interval        
----------------------------
 @ 11 mons 28 days 22 hours
(1 row)

select make_interval() = make_interval(years := 0, months := 0, weeks := 0, days := 0, mins := 0, secs := 0.0);
 ?column? 
----------
 t
(1 row)

select make_interval(hours := -2, mins := -10, secs := -25.3);
          make_interval          
---------------------------------
 @ 2 hours 10 mins 25.3 secs ago
(1 row)

select make_interval(years := 'inf'::float::int);
ERROR:  integer out of range
select make_interval(months := 'NaN'::float::int);
ERROR:  integer out of range
select make_interval(secs := 'inf');
ERROR:  interval out of range
select make_interval(secs := 'NaN');
ERROR:  interval out of range
select make_interval(secs := 7e12);
           make_interval            
------------------------------------
 @ 1944444444 hours 26 mins 40 secs
(1 row)

--
-- test EXTRACT
--
SELECT f1,
    EXTRACT(MICROSECOND FROM f1) AS MICROSECOND,
    EXTRACT(MILLISECOND FROM f1) AS MILLISECOND,
    EXTRACT(SECOND FROM f1) AS SECOND,
    EXTRACT(MINUTE FROM f1) AS MINUTE,
    EXTRACT(HOUR FROM f1) AS HOUR,
    EXTRACT(DAY FROM f1) AS DAY,
    EXTRACT(MONTH FROM f1) AS MONTH,
    EXTRACT(QUARTER FROM f1) AS QUARTER,
    EXTRACT(YEAR FROM f1) AS YEAR,
    EXTRACT(DECADE FROM f1) AS DECADE,
    EXTRACT(CENTURY FROM f1) AS CENTURY,
    EXTRACT(MILLENNIUM FROM f1) AS MILLENNIUM,
    EXTRACT(EPOCH FROM f1) AS EPOCH
    FROM INTERVAL_TBL;
              f1               | microsecond | millisecond |   second   | minute | hour | day | month | quarter | year | decade | century | millennium |       epoch       
-------------------------------+-------------+-------------+------------+--------+------+-----+-------+---------+------+--------+---------+------------+-------------------
 @ 1 min                       |           0 |       0.000 |   0.000000 |      1 |    0 |   0 |     0 |       1 |    0 |      0 |       0 |          0 |         60.000000
 @ 5 hours                     |           0 |       0.000 |   0.000000 |      0 |    5 |   0 |     0 |       1 |    0 |      0 |       0 |          0 |      18000.000000
 @ 10 days                     |           0 |       0.000 |   0.000000 |      0 |    0 |  10 |     0 |       1 |    0 |      0 |       0 |          0 |     864000.000000
 @ 34 years                    |           0 |       0.000 |   0.000000 |      0 |    0 |   0 |     0 |       1 |   34 |      3 |       0 |          0 | 1072958400.000000
 @ 3 mons                      |           0 |       0.000 |   0.000000 |      0 |    0 |   0 |     3 |       2 |    0 |      0 |       0 |          0 |    7776000.000000
 @ 14 secs ago                 |   -14000000 |  -14000.000 | -14.000000 |      0 |    0 |   0 |     0 |       1 |    0 |      0 |       0 |          0 |        -14.000000
 @ 1 day 2 hours 3 mins 4 secs |     4000000 |    4000.000 |   4.000000 |      3 |    2 |   1 |     0 |       1 |    0 |      0 |       0 |          0 |      93784.000000
 @ 6 years                     |           0 |       0.000 |   0.000000 |      0 |    0 |   0 |     0 |       1 |    6 |      0 |       0 |          0 |  189345600.000000
 @ 5 mons                      |           0 |       0.000 |   0.000000 |      0 |    0 |   0 |     5 |       2 |    0 |      0 |       0 |          0 |   12960000.000000
 @ 5 mons 12 hours             |           0 |       0.000 |   0.000000 |      0 |   12 |   0 |     5 |       2 |    0 |      0 |       0 |          0 |   13003200.000000
(10 rows)

SELECT EXTRACT(FORTNIGHT FROM INTERVAL '2 days');  -- error
ERROR:  unit "fortnight" not recognized for type interval
SELECT EXTRACT(TIMEZONE FROM INTERVAL '2 days');  -- error
ERROR:  unit "timezone" not supported for type interval
SELECT EXTRACT(DECADE FROM INTERVAL '100 y');
 extract 
---------
      10
(1 row)

SELECT EXTRACT(DECADE FROM INTERVAL '99 y');
 extract 
---------
       9
(1 row)

SELECT EXTRACT(DECADE FROM INTERVAL '-99 y');
 extract 
---------
      -9
(1 row)

SELECT EXTRACT(DECADE FROM INTERVAL '-100 y');
 extract 
---------
     -10
(1 row)

SELECT EXTRACT(CENTURY FROM INTERVAL '100 y');
 extract 
---------
       1
(1 row)

SELECT EXTRACT(CENTURY FROM INTERVAL '99 y');
 extract 
---------
       0
(1 row)

SELECT EXTRACT(CENTURY FROM INTERVAL '-99 y');
 extract 
---------
       0
(1 row)

SELECT EXTRACT(CENTURY FROM INTERVAL '-100 y');
 extract 
---------
      -1
(1 row)

-- date_part implementation is mostly the same as extract, so only
-- test a few cases for additional coverage.
SELECT f1,
    date_part('microsecond', f1) AS microsecond,
    date_part('millisecond', f1) AS millisecond,
    date_part('second', f1) AS second,
    date_part('epoch', f1) AS epoch
    FROM INTERVAL_TBL;
              f1               | microsecond | millisecond | second |   epoch    
-------------------------------+-------------+-------------+--------+------------
 @ 1 min                       |           0 |           0 |      0 |         60
 @ 5 hours                     |           0 |           0 |      0 |      18000
 @ 10 days                     |           0 |           0 |      0 |     864000
 @ 34 years                    |           0 |           0 |      0 | 1072958400
 @ 3 mons                      |           0 |           0 |      0 |    7776000
 @ 14 secs ago                 |   -14000000 |      -14000 |    -14 |        -14
 @ 1 day 2 hours 3 mins 4 secs |     4000000 |        4000 |      4 |      93784
 @ 6 years                     |           0 |           0 |      0 |  189345600
 @ 5 mons                      |           0 |           0 |      0 |   12960000
 @ 5 mons 12 hours             |           0 |           0 |      0 |   13003200
(10 rows)

-- internal overflow test case
SELECT extract(epoch from interval '1000000000 days');
        extract        
-----------------------
 86400000000000.000000
(1 row)