summaryrefslogtreecommitdiffstats
path: root/src/test/regress/expected/timestamp.out
blob: 2ee8712a96c24be71e806a37789cc33ee975ca40 (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
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
--
-- TIMESTAMP
--
CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone);
-- Test shorthand input values
-- We can't just "select" the results since they aren't constants; test for
-- equality instead.  We can do that by running the test inside a transaction
-- block, within which the value of 'now' shouldn't change, and so these
-- related values shouldn't either.
BEGIN;
INSERT INTO TIMESTAMP_TBL VALUES ('today');
INSERT INTO TIMESTAMP_TBL VALUES ('yesterday');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow');
-- time zone should be ignored by this data type
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow EST');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow zulu');
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'today';
 one 
-----
   1
(1 row)

SELECT count(*) AS Three FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'tomorrow';
 three 
-------
     3
(1 row)

SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'yesterday';
 one 
-----
   1
(1 row)

COMMIT;
DELETE FROM TIMESTAMP_TBL;
-- Verify that 'now' *does* change over a reasonable interval such as 100 msec,
-- and that it doesn't change over the same interval within a transaction block
INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);
 pg_sleep 
----------
 
(1 row)

BEGIN;
INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);
 pg_sleep 
----------
 
(1 row)

INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);
 pg_sleep 
----------
 
(1 row)

SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now';
 two 
-----
   2
(1 row)

SELECT count(d1) AS three, count(DISTINCT d1) AS two FROM TIMESTAMP_TBL;
 three | two 
-------+-----
     3 |   2
(1 row)

COMMIT;
TRUNCATE TIMESTAMP_TBL;
-- Special values
INSERT INTO TIMESTAMP_TBL VALUES ('-infinity');
INSERT INTO TIMESTAMP_TBL VALUES ('infinity');
INSERT INTO TIMESTAMP_TBL VALUES ('epoch');
-- Postgres v6.0 standard output format
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
-- Variations on Postgres v6.1 standard output format
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.000001 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.999999 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.4 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.5 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.6 1997 PST');
-- ISO 8601 format
INSERT INTO TIMESTAMP_TBL VALUES ('1997-01-02');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-01-02 03:04:05');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01-08');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01-0800');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01 -08:00');
INSERT INTO TIMESTAMP_TBL VALUES ('19970210 173201 -0800');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-06-10 17:32:01 -07:00');
INSERT INTO TIMESTAMP_TBL VALUES ('2001-09-22T18:19:20');
-- POSIX format (note that the timezone abbrev is just decoration here)
INSERT INTO TIMESTAMP_TBL VALUES ('2000-03-15 08:14:01 GMT+8');
INSERT INTO TIMESTAMP_TBL VALUES ('2000-03-15 13:14:02 GMT-1');
INSERT INTO TIMESTAMP_TBL VALUES ('2000-03-15 12:14:03 GMT-2');
INSERT INTO TIMESTAMP_TBL VALUES ('2000-03-15 03:14:04 PST+8');
INSERT INTO TIMESTAMP_TBL VALUES ('2000-03-15 02:14:05 MST+7:00');
-- Variations for acceptable input formats
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997 -0800');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 5:32PM 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('1997/02/10 17:32:01-0800');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb-10-1997 17:32:01 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('02-10-1997 17:32:01 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('19970210 173201 PST');
set datestyle to ymd;
INSERT INTO TIMESTAMP_TBL VALUES ('97FEB10 5:32:01PM UTC');
INSERT INTO TIMESTAMP_TBL VALUES ('97/02/10 17:32:01 UTC');
reset datestyle;
INSERT INTO TIMESTAMP_TBL VALUES ('1997.041 17:32:01 UTC');
INSERT INTO TIMESTAMP_TBL VALUES ('19970210 173201 America/New_York');
-- this fails (even though TZ is a no-op, we still look it up)
INSERT INTO TIMESTAMP_TBL VALUES ('19970710 173201 America/Does_not_exist');
ERROR:  time zone "america/does_not_exist" not recognized
LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('19970710 173201 America/D...
                                          ^
-- Check date conversion and date arithmetic
INSERT INTO TIMESTAMP_TBL VALUES ('1997-06-10 18:32:01 PDT');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 11 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 12 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 13 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 14 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 15 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 0097 BC');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 0097');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 0597');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1097');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1697');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1797');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1897');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 2097');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 28 17:32:01 1996');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1996');
INSERT INTO TIMESTAMP_TBL VALUES ('Mar 01 17:32:01 1996');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 30 17:32:01 1996');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1996');
INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 28 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1997');
ERROR:  date/time field value out of range: "Feb 29 17:32:01 1997"
LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1997');
                                          ^
INSERT INTO TIMESTAMP_TBL VALUES ('Mar 01 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 30 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1999');
INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2000');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 2000');
INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2001');
-- Currently unsupported syntax and ranges
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 -0097');
ERROR:  time zone displacement out of range: "Feb 16 17:32:01 -0097"
LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 -0097');
                                          ^
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 5097 BC');
ERROR:  timestamp out of range: "Feb 16 17:32:01 5097 BC"
LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 5097 BC')...
                                          ^
SELECT d1 FROM TIMESTAMP_TBL;
             d1              
-----------------------------
 -infinity
 infinity
 Thu Jan 01 00:00:00 1970
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:02 1997
 Mon Feb 10 17:32:01.4 1997
 Mon Feb 10 17:32:01.5 1997
 Mon Feb 10 17:32:01.6 1997
 Thu Jan 02 00:00:00 1997
 Thu Jan 02 03:04:05 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Jun 10 17:32:01 1997
 Sat Sep 22 18:19:20 2001
 Wed Mar 15 08:14:01 2000
 Wed Mar 15 13:14:02 2000
 Wed Mar 15 12:14:03 2000
 Wed Mar 15 03:14:04 2000
 Wed Mar 15 02:14:05 2000
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:00 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Jun 10 18:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Feb 11 17:32:01 1997
 Wed Feb 12 17:32:01 1997
 Thu Feb 13 17:32:01 1997
 Fri Feb 14 17:32:01 1997
 Sat Feb 15 17:32:01 1997
 Sun Feb 16 17:32:01 1997
 Tue Feb 16 17:32:01 0097 BC
 Sat Feb 16 17:32:01 0097
 Thu Feb 16 17:32:01 0597
 Tue Feb 16 17:32:01 1097
 Sat Feb 16 17:32:01 1697
 Thu Feb 16 17:32:01 1797
 Tue Feb 16 17:32:01 1897
 Sun Feb 16 17:32:01 1997
 Sat Feb 16 17:32:01 2097
 Wed Feb 28 17:32:01 1996
 Thu Feb 29 17:32:01 1996
 Fri Mar 01 17:32:01 1996
 Mon Dec 30 17:32:01 1996
 Tue Dec 31 17:32:01 1996
 Wed Jan 01 17:32:01 1997
 Fri Feb 28 17:32:01 1997
 Sat Mar 01 17:32:01 1997
 Tue Dec 30 17:32:01 1997
 Wed Dec 31 17:32:01 1997
 Fri Dec 31 17:32:01 1999
 Sat Jan 01 17:32:01 2000
 Sun Dec 31 17:32:01 2000
 Mon Jan 01 17:32:01 2001
(65 rows)

-- Check behavior at the boundaries of the timestamp range
SELECT '4714-11-24 00:00:00 BC'::timestamp;
          timestamp          
-----------------------------
 Mon Nov 24 00:00:00 4714 BC
(1 row)

SELECT '4714-11-23 23:59:59 BC'::timestamp;  -- out of range
ERROR:  timestamp out of range: "4714-11-23 23:59:59 BC"
LINE 1: SELECT '4714-11-23 23:59:59 BC'::timestamp;
               ^
SELECT '294276-12-31 23:59:59'::timestamp;
         timestamp          
----------------------------
 Sun Dec 31 23:59:59 294276
(1 row)

SELECT '294277-01-01 00:00:00'::timestamp;  -- out of range
ERROR:  timestamp out of range: "294277-01-01 00:00:00"
LINE 1: SELECT '294277-01-01 00:00:00'::timestamp;
               ^
-- Demonstrate functions and operators
SELECT d1 FROM TIMESTAMP_TBL
   WHERE d1 > timestamp without time zone '1997-01-02';
             d1             
----------------------------
 infinity
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:02 1997
 Mon Feb 10 17:32:01.4 1997
 Mon Feb 10 17:32:01.5 1997
 Mon Feb 10 17:32:01.6 1997
 Thu Jan 02 03:04:05 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Jun 10 17:32:01 1997
 Sat Sep 22 18:19:20 2001
 Wed Mar 15 08:14:01 2000
 Wed Mar 15 13:14:02 2000
 Wed Mar 15 12:14:03 2000
 Wed Mar 15 03:14:04 2000
 Wed Mar 15 02:14:05 2000
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:00 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Jun 10 18:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Feb 11 17:32:01 1997
 Wed Feb 12 17:32:01 1997
 Thu Feb 13 17:32:01 1997
 Fri Feb 14 17:32:01 1997
 Sat Feb 15 17:32:01 1997
 Sun Feb 16 17:32:01 1997
 Sun Feb 16 17:32:01 1997
 Sat Feb 16 17:32:01 2097
 Fri Feb 28 17:32:01 1997
 Sat Mar 01 17:32:01 1997
 Tue Dec 30 17:32:01 1997
 Wed Dec 31 17:32:01 1997
 Fri Dec 31 17:32:01 1999
 Sat Jan 01 17:32:01 2000
 Sun Dec 31 17:32:01 2000
 Mon Jan 01 17:32:01 2001
(49 rows)

SELECT d1 FROM TIMESTAMP_TBL
   WHERE d1 < timestamp without time zone '1997-01-02';
             d1              
-----------------------------
 -infinity
 Thu Jan 01 00:00:00 1970
 Tue Feb 16 17:32:01 0097 BC
 Sat Feb 16 17:32:01 0097
 Thu Feb 16 17:32:01 0597
 Tue Feb 16 17:32:01 1097
 Sat Feb 16 17:32:01 1697
 Thu Feb 16 17:32:01 1797
 Tue Feb 16 17:32:01 1897
 Wed Feb 28 17:32:01 1996
 Thu Feb 29 17:32:01 1996
 Fri Mar 01 17:32:01 1996
 Mon Dec 30 17:32:01 1996
 Tue Dec 31 17:32:01 1996
 Wed Jan 01 17:32:01 1997
(15 rows)

SELECT d1 FROM TIMESTAMP_TBL
   WHERE d1 = timestamp without time zone '1997-01-02';
            d1            
--------------------------
 Thu Jan 02 00:00:00 1997
(1 row)

SELECT d1 FROM TIMESTAMP_TBL
   WHERE d1 != timestamp without time zone '1997-01-02';
             d1              
-----------------------------
 -infinity
 infinity
 Thu Jan 01 00:00:00 1970
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:02 1997
 Mon Feb 10 17:32:01.4 1997
 Mon Feb 10 17:32:01.5 1997
 Mon Feb 10 17:32:01.6 1997
 Thu Jan 02 03:04:05 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Jun 10 17:32:01 1997
 Sat Sep 22 18:19:20 2001
 Wed Mar 15 08:14:01 2000
 Wed Mar 15 13:14:02 2000
 Wed Mar 15 12:14:03 2000
 Wed Mar 15 03:14:04 2000
 Wed Mar 15 02:14:05 2000
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:00 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Jun 10 18:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Feb 11 17:32:01 1997
 Wed Feb 12 17:32:01 1997
 Thu Feb 13 17:32:01 1997
 Fri Feb 14 17:32:01 1997
 Sat Feb 15 17:32:01 1997
 Sun Feb 16 17:32:01 1997
 Tue Feb 16 17:32:01 0097 BC
 Sat Feb 16 17:32:01 0097
 Thu Feb 16 17:32:01 0597
 Tue Feb 16 17:32:01 1097
 Sat Feb 16 17:32:01 1697
 Thu Feb 16 17:32:01 1797
 Tue Feb 16 17:32:01 1897
 Sun Feb 16 17:32:01 1997
 Sat Feb 16 17:32:01 2097
 Wed Feb 28 17:32:01 1996
 Thu Feb 29 17:32:01 1996
 Fri Mar 01 17:32:01 1996
 Mon Dec 30 17:32:01 1996
 Tue Dec 31 17:32:01 1996
 Wed Jan 01 17:32:01 1997
 Fri Feb 28 17:32:01 1997
 Sat Mar 01 17:32:01 1997
 Tue Dec 30 17:32:01 1997
 Wed Dec 31 17:32:01 1997
 Fri Dec 31 17:32:01 1999
 Sat Jan 01 17:32:01 2000
 Sun Dec 31 17:32:01 2000
 Mon Jan 01 17:32:01 2001
(64 rows)

SELECT d1 FROM TIMESTAMP_TBL
   WHERE d1 <= timestamp without time zone '1997-01-02';
             d1              
-----------------------------
 -infinity
 Thu Jan 01 00:00:00 1970
 Thu Jan 02 00:00:00 1997
 Tue Feb 16 17:32:01 0097 BC
 Sat Feb 16 17:32:01 0097
 Thu Feb 16 17:32:01 0597
 Tue Feb 16 17:32:01 1097
 Sat Feb 16 17:32:01 1697
 Thu Feb 16 17:32:01 1797
 Tue Feb 16 17:32:01 1897
 Wed Feb 28 17:32:01 1996
 Thu Feb 29 17:32:01 1996
 Fri Mar 01 17:32:01 1996
 Mon Dec 30 17:32:01 1996
 Tue Dec 31 17:32:01 1996
 Wed Jan 01 17:32:01 1997
(16 rows)

SELECT d1 FROM TIMESTAMP_TBL
   WHERE d1 >= timestamp without time zone '1997-01-02';
             d1             
----------------------------
 infinity
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:02 1997
 Mon Feb 10 17:32:01.4 1997
 Mon Feb 10 17:32:01.5 1997
 Mon Feb 10 17:32:01.6 1997
 Thu Jan 02 00:00:00 1997
 Thu Jan 02 03:04:05 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Jun 10 17:32:01 1997
 Sat Sep 22 18:19:20 2001
 Wed Mar 15 08:14:01 2000
 Wed Mar 15 13:14:02 2000
 Wed Mar 15 12:14:03 2000
 Wed Mar 15 03:14:04 2000
 Wed Mar 15 02:14:05 2000
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:00 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Jun 10 18:32:01 1997
 Mon Feb 10 17:32:01 1997
 Tue Feb 11 17:32:01 1997
 Wed Feb 12 17:32:01 1997
 Thu Feb 13 17:32:01 1997
 Fri Feb 14 17:32:01 1997
 Sat Feb 15 17:32:01 1997
 Sun Feb 16 17:32:01 1997
 Sun Feb 16 17:32:01 1997
 Sat Feb 16 17:32:01 2097
 Fri Feb 28 17:32:01 1997
 Sat Mar 01 17:32:01 1997
 Tue Dec 30 17:32:01 1997
 Wed Dec 31 17:32:01 1997
 Fri Dec 31 17:32:01 1999
 Sat Jan 01 17:32:01 2000
 Sun Dec 31 17:32:01 2000
 Mon Jan 01 17:32:01 2001
(50 rows)

SELECT d1 - timestamp without time zone '1997-01-02' AS diff
   FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
                  diff                  
----------------------------------------
 @ 9863 days ago
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 2 secs
 @ 39 days 17 hours 32 mins 1.4 secs
 @ 39 days 17 hours 32 mins 1.5 secs
 @ 39 days 17 hours 32 mins 1.6 secs
 @ 0
 @ 3 hours 4 mins 5 secs
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 159 days 17 hours 32 mins 1 sec
 @ 1724 days 18 hours 19 mins 20 secs
 @ 1168 days 8 hours 14 mins 1 sec
 @ 1168 days 13 hours 14 mins 2 secs
 @ 1168 days 12 hours 14 mins 3 secs
 @ 1168 days 3 hours 14 mins 4 secs
 @ 1168 days 2 hours 14 mins 5 secs
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 159 days 18 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 40 days 17 hours 32 mins 1 sec
 @ 41 days 17 hours 32 mins 1 sec
 @ 42 days 17 hours 32 mins 1 sec
 @ 43 days 17 hours 32 mins 1 sec
 @ 44 days 17 hours 32 mins 1 sec
 @ 45 days 17 hours 32 mins 1 sec
 @ 45 days 17 hours 32 mins 1 sec
 @ 308 days 6 hours 27 mins 59 secs ago
 @ 307 days 6 hours 27 mins 59 secs ago
 @ 306 days 6 hours 27 mins 59 secs ago
 @ 2 days 6 hours 27 mins 59 secs ago
 @ 1 day 6 hours 27 mins 59 secs ago
 @ 6 hours 27 mins 59 secs ago
 @ 57 days 17 hours 32 mins 1 sec
 @ 58 days 17 hours 32 mins 1 sec
 @ 362 days 17 hours 32 mins 1 sec
 @ 363 days 17 hours 32 mins 1 sec
 @ 1093 days 17 hours 32 mins 1 sec
 @ 1094 days 17 hours 32 mins 1 sec
 @ 1459 days 17 hours 32 mins 1 sec
 @ 1460 days 17 hours 32 mins 1 sec
(55 rows)

SELECT date_trunc( 'week', timestamp '2004-02-29 15:44:17.71393' ) AS week_trunc;
        week_trunc        
--------------------------
 Mon Feb 23 00:00:00 2004
(1 row)

-- verify date_bin behaves the same as date_trunc for relevant intervals
-- case 1: AD dates, origin < input
SELECT
  str,
  interval,
  date_trunc(str, ts) = date_bin(interval::interval, ts, timestamp '2001-01-01') AS equal
FROM (
  VALUES
  ('week', '7 d'),
  ('day', '1 d'),
  ('hour', '1 h'),
  ('minute', '1 m'),
  ('second', '1 s'),
  ('millisecond', '1 ms'),
  ('microsecond', '1 us')
) intervals (str, interval),
(VALUES (timestamp '2020-02-29 15:44:17.71393')) ts (ts);
     str     | interval | equal 
-------------+----------+-------
 week        | 7 d      | t
 day         | 1 d      | t
 hour        | 1 h      | t
 minute      | 1 m      | t
 second      | 1 s      | t
 millisecond | 1 ms     | t
 microsecond | 1 us     | t
(7 rows)

-- case 2: BC dates, origin < input
SELECT
  str,
  interval,
  date_trunc(str, ts) = date_bin(interval::interval, ts, timestamp '2000-01-01 BC') AS equal
FROM (
  VALUES
  ('week', '7 d'),
  ('day', '1 d'),
  ('hour', '1 h'),
  ('minute', '1 m'),
  ('second', '1 s'),
  ('millisecond', '1 ms'),
  ('microsecond', '1 us')
) intervals (str, interval),
(VALUES (timestamp '0055-6-10 15:44:17.71393 BC')) ts (ts);
     str     | interval | equal 
-------------+----------+-------
 week        | 7 d      | t
 day         | 1 d      | t
 hour        | 1 h      | t
 minute      | 1 m      | t
 second      | 1 s      | t
 millisecond | 1 ms     | t
 microsecond | 1 us     | t
(7 rows)

-- case 3: AD dates, origin > input
SELECT
  str,
  interval,
  date_trunc(str, ts) = date_bin(interval::interval, ts, timestamp '2020-03-02') AS equal
FROM (
  VALUES
  ('week', '7 d'),
  ('day', '1 d'),
  ('hour', '1 h'),
  ('minute', '1 m'),
  ('second', '1 s'),
  ('millisecond', '1 ms'),
  ('microsecond', '1 us')
) intervals (str, interval),
(VALUES (timestamp '2020-02-29 15:44:17.71393')) ts (ts);
     str     | interval | equal 
-------------+----------+-------
 week        | 7 d      | t
 day         | 1 d      | t
 hour        | 1 h      | t
 minute      | 1 m      | t
 second      | 1 s      | t
 millisecond | 1 ms     | t
 microsecond | 1 us     | t
(7 rows)

-- case 4: BC dates, origin > input
SELECT
  str,
  interval,
  date_trunc(str, ts) = date_bin(interval::interval, ts, timestamp '0055-06-17 BC') AS equal
FROM (
  VALUES
  ('week', '7 d'),
  ('day', '1 d'),
  ('hour', '1 h'),
  ('minute', '1 m'),
  ('second', '1 s'),
  ('millisecond', '1 ms'),
  ('microsecond', '1 us')
) intervals (str, interval),
(VALUES (timestamp '0055-6-10 15:44:17.71393 BC')) ts (ts);
     str     | interval | equal 
-------------+----------+-------
 week        | 7 d      | t
 day         | 1 d      | t
 hour        | 1 h      | t
 minute      | 1 m      | t
 second      | 1 s      | t
 millisecond | 1 ms     | t
 microsecond | 1 us     | t
(7 rows)

-- bin timestamps into arbitrary intervals
SELECT
  interval,
  ts,
  origin,
  date_bin(interval::interval, ts, origin)
FROM (
  VALUES
  ('15 days'),
  ('2 hours'),
  ('1 hour 30 minutes'),
  ('15 minutes'),
  ('10 seconds'),
  ('100 milliseconds'),
  ('250 microseconds')
) intervals (interval),
(VALUES (timestamp '2020-02-11 15:44:17.71393')) ts (ts),
(VALUES (timestamp '2001-01-01')) origin (origin);
     interval      |               ts               |          origin          |            date_bin            
-------------------+--------------------------------+--------------------------+--------------------------------
 15 days           | Tue Feb 11 15:44:17.71393 2020 | Mon Jan 01 00:00:00 2001 | Thu Feb 06 00:00:00 2020
 2 hours           | Tue Feb 11 15:44:17.71393 2020 | Mon Jan 01 00:00:00 2001 | Tue Feb 11 14:00:00 2020
 1 hour 30 minutes | Tue Feb 11 15:44:17.71393 2020 | Mon Jan 01 00:00:00 2001 | Tue Feb 11 15:00:00 2020
 15 minutes        | Tue Feb 11 15:44:17.71393 2020 | Mon Jan 01 00:00:00 2001 | Tue Feb 11 15:30:00 2020
 10 seconds        | Tue Feb 11 15:44:17.71393 2020 | Mon Jan 01 00:00:00 2001 | Tue Feb 11 15:44:10 2020
 100 milliseconds  | Tue Feb 11 15:44:17.71393 2020 | Mon Jan 01 00:00:00 2001 | Tue Feb 11 15:44:17.7 2020
 250 microseconds  | Tue Feb 11 15:44:17.71393 2020 | Mon Jan 01 00:00:00 2001 | Tue Feb 11 15:44:17.71375 2020
(7 rows)

-- shift bins using the origin parameter:
SELECT date_bin('5 min'::interval, timestamp '2020-02-01 01:01:01', timestamp '2020-02-01 00:02:30');
         date_bin         
--------------------------
 Sat Feb 01 00:57:30 2020
(1 row)

-- test roundoff edge case when source < origin
SELECT date_bin('30 minutes'::interval, timestamp '2024-02-01 15:00:00', timestamp '2024-02-01 17:00:00');
         date_bin         
--------------------------
 Thu Feb 01 15:00:00 2024
(1 row)

-- disallow intervals with months or years
SELECT date_bin('5 months'::interval, timestamp '2020-02-01 01:01:01', timestamp '2001-01-01');
ERROR:  timestamps cannot be binned into intervals containing months or years
SELECT date_bin('5 years'::interval,  timestamp '2020-02-01 01:01:01', timestamp '2001-01-01');
ERROR:  timestamps cannot be binned into intervals containing months or years
-- disallow zero intervals
SELECT date_bin('0 days'::interval, timestamp '1970-01-01 01:00:00' , timestamp '1970-01-01 00:00:00');
ERROR:  stride must be greater than zero
-- disallow negative intervals
SELECT date_bin('-2 days'::interval, timestamp '1970-01-01 01:00:00' , timestamp '1970-01-01 00:00:00');
ERROR:  stride must be greater than zero
-- test overflow cases
select date_bin('15 minutes'::interval, timestamp '294276-12-30', timestamp '4000-12-20 BC');
ERROR:  interval out of range
select date_bin('200000000 days'::interval, '2024-02-01'::timestamp, '2024-01-01'::timestamp);
ERROR:  interval out of range
select date_bin('365000 days'::interval, '4400-01-01 BC'::timestamp, '4000-01-01 BC'::timestamp);
ERROR:  timestamp out of range
-- Test casting within a BETWEEN qualifier
SELECT d1 - timestamp without time zone '1997-01-02' AS diff
  FROM TIMESTAMP_TBL
  WHERE d1 BETWEEN timestamp without time zone '1902-01-01'
   AND timestamp without time zone '2038-01-01';
                  diff                  
----------------------------------------
 @ 9863 days ago
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 2 secs
 @ 39 days 17 hours 32 mins 1.4 secs
 @ 39 days 17 hours 32 mins 1.5 secs
 @ 39 days 17 hours 32 mins 1.6 secs
 @ 0
 @ 3 hours 4 mins 5 secs
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 159 days 17 hours 32 mins 1 sec
 @ 1724 days 18 hours 19 mins 20 secs
 @ 1168 days 8 hours 14 mins 1 sec
 @ 1168 days 13 hours 14 mins 2 secs
 @ 1168 days 12 hours 14 mins 3 secs
 @ 1168 days 3 hours 14 mins 4 secs
 @ 1168 days 2 hours 14 mins 5 secs
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 159 days 18 hours 32 mins 1 sec
 @ 39 days 17 hours 32 mins 1 sec
 @ 40 days 17 hours 32 mins 1 sec
 @ 41 days 17 hours 32 mins 1 sec
 @ 42 days 17 hours 32 mins 1 sec
 @ 43 days 17 hours 32 mins 1 sec
 @ 44 days 17 hours 32 mins 1 sec
 @ 45 days 17 hours 32 mins 1 sec
 @ 45 days 17 hours 32 mins 1 sec
 @ 308 days 6 hours 27 mins 59 secs ago
 @ 307 days 6 hours 27 mins 59 secs ago
 @ 306 days 6 hours 27 mins 59 secs ago
 @ 2 days 6 hours 27 mins 59 secs ago
 @ 1 day 6 hours 27 mins 59 secs ago
 @ 6 hours 27 mins 59 secs ago
 @ 57 days 17 hours 32 mins 1 sec
 @ 58 days 17 hours 32 mins 1 sec
 @ 362 days 17 hours 32 mins 1 sec
 @ 363 days 17 hours 32 mins 1 sec
 @ 1093 days 17 hours 32 mins 1 sec
 @ 1094 days 17 hours 32 mins 1 sec
 @ 1459 days 17 hours 32 mins 1 sec
 @ 1460 days 17 hours 32 mins 1 sec
(55 rows)

-- DATE_PART (timestamp_part)
SELECT d1 as "timestamp",
   date_part( 'year', d1) AS year, date_part( 'month', d1) AS month,
   date_part( 'day', d1) AS day, date_part( 'hour', d1) AS hour,
   date_part( 'minute', d1) AS minute, date_part( 'second', d1) AS second
   FROM TIMESTAMP_TBL;
          timestamp          |   year    | month | day | hour | minute | second 
-----------------------------+-----------+-------+-----+------+--------+--------
 -infinity                   | -Infinity |       |     |      |        |       
 infinity                    |  Infinity |       |     |      |        |       
 Thu Jan 01 00:00:00 1970    |      1970 |     1 |   1 |    0 |      0 |      0
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:02 1997    |      1997 |     2 |  10 |   17 |     32 |      2
 Mon Feb 10 17:32:01.4 1997  |      1997 |     2 |  10 |   17 |     32 |    1.4
 Mon Feb 10 17:32:01.5 1997  |      1997 |     2 |  10 |   17 |     32 |    1.5
 Mon Feb 10 17:32:01.6 1997  |      1997 |     2 |  10 |   17 |     32 |    1.6
 Thu Jan 02 00:00:00 1997    |      1997 |     1 |   2 |    0 |      0 |      0
 Thu Jan 02 03:04:05 1997    |      1997 |     1 |   2 |    3 |      4 |      5
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Tue Jun 10 17:32:01 1997    |      1997 |     6 |  10 |   17 |     32 |      1
 Sat Sep 22 18:19:20 2001    |      2001 |     9 |  22 |   18 |     19 |     20
 Wed Mar 15 08:14:01 2000    |      2000 |     3 |  15 |    8 |     14 |      1
 Wed Mar 15 13:14:02 2000    |      2000 |     3 |  15 |   13 |     14 |      2
 Wed Mar 15 12:14:03 2000    |      2000 |     3 |  15 |   12 |     14 |      3
 Wed Mar 15 03:14:04 2000    |      2000 |     3 |  15 |    3 |     14 |      4
 Wed Mar 15 02:14:05 2000    |      2000 |     3 |  15 |    2 |     14 |      5
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:00 1997    |      1997 |     2 |  10 |   17 |     32 |      0
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Tue Jun 10 18:32:01 1997    |      1997 |     6 |  10 |   18 |     32 |      1
 Mon Feb 10 17:32:01 1997    |      1997 |     2 |  10 |   17 |     32 |      1
 Tue Feb 11 17:32:01 1997    |      1997 |     2 |  11 |   17 |     32 |      1
 Wed Feb 12 17:32:01 1997    |      1997 |     2 |  12 |   17 |     32 |      1
 Thu Feb 13 17:32:01 1997    |      1997 |     2 |  13 |   17 |     32 |      1
 Fri Feb 14 17:32:01 1997    |      1997 |     2 |  14 |   17 |     32 |      1
 Sat Feb 15 17:32:01 1997    |      1997 |     2 |  15 |   17 |     32 |      1
 Sun Feb 16 17:32:01 1997    |      1997 |     2 |  16 |   17 |     32 |      1
 Tue Feb 16 17:32:01 0097 BC |       -97 |     2 |  16 |   17 |     32 |      1
 Sat Feb 16 17:32:01 0097    |        97 |     2 |  16 |   17 |     32 |      1
 Thu Feb 16 17:32:01 0597    |       597 |     2 |  16 |   17 |     32 |      1
 Tue Feb 16 17:32:01 1097    |      1097 |     2 |  16 |   17 |     32 |      1
 Sat Feb 16 17:32:01 1697    |      1697 |     2 |  16 |   17 |     32 |      1
 Thu Feb 16 17:32:01 1797    |      1797 |     2 |  16 |   17 |     32 |      1
 Tue Feb 16 17:32:01 1897    |      1897 |     2 |  16 |   17 |     32 |      1
 Sun Feb 16 17:32:01 1997    |      1997 |     2 |  16 |   17 |     32 |      1
 Sat Feb 16 17:32:01 2097    |      2097 |     2 |  16 |   17 |     32 |      1
 Wed Feb 28 17:32:01 1996    |      1996 |     2 |  28 |   17 |     32 |      1
 Thu Feb 29 17:32:01 1996    |      1996 |     2 |  29 |   17 |     32 |      1
 Fri Mar 01 17:32:01 1996    |      1996 |     3 |   1 |   17 |     32 |      1
 Mon Dec 30 17:32:01 1996    |      1996 |    12 |  30 |   17 |     32 |      1
 Tue Dec 31 17:32:01 1996    |      1996 |    12 |  31 |   17 |     32 |      1
 Wed Jan 01 17:32:01 1997    |      1997 |     1 |   1 |   17 |     32 |      1
 Fri Feb 28 17:32:01 1997    |      1997 |     2 |  28 |   17 |     32 |      1
 Sat Mar 01 17:32:01 1997    |      1997 |     3 |   1 |   17 |     32 |      1
 Tue Dec 30 17:32:01 1997    |      1997 |    12 |  30 |   17 |     32 |      1
 Wed Dec 31 17:32:01 1997    |      1997 |    12 |  31 |   17 |     32 |      1
 Fri Dec 31 17:32:01 1999    |      1999 |    12 |  31 |   17 |     32 |      1
 Sat Jan 01 17:32:01 2000    |      2000 |     1 |   1 |   17 |     32 |      1
 Sun Dec 31 17:32:01 2000    |      2000 |    12 |  31 |   17 |     32 |      1
 Mon Jan 01 17:32:01 2001    |      2001 |     1 |   1 |   17 |     32 |      1
(65 rows)

SELECT d1 as "timestamp",
   date_part( 'quarter', d1) AS quarter, date_part( 'msec', d1) AS msec,
   date_part( 'usec', d1) AS usec
   FROM TIMESTAMP_TBL;
          timestamp          | quarter | msec  |   usec   
-----------------------------+---------+-------+----------
 -infinity                   |         |       |         
 infinity                    |         |       |         
 Thu Jan 01 00:00:00 1970    |       1 |     0 |        0
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:02 1997    |       1 |  2000 |  2000000
 Mon Feb 10 17:32:01.4 1997  |       1 |  1400 |  1400000
 Mon Feb 10 17:32:01.5 1997  |       1 |  1500 |  1500000
 Mon Feb 10 17:32:01.6 1997  |       1 |  1600 |  1600000
 Thu Jan 02 00:00:00 1997    |       1 |     0 |        0
 Thu Jan 02 03:04:05 1997    |       1 |  5000 |  5000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Tue Jun 10 17:32:01 1997    |       2 |  1000 |  1000000
 Sat Sep 22 18:19:20 2001    |       3 | 20000 | 20000000
 Wed Mar 15 08:14:01 2000    |       1 |  1000 |  1000000
 Wed Mar 15 13:14:02 2000    |       1 |  2000 |  2000000
 Wed Mar 15 12:14:03 2000    |       1 |  3000 |  3000000
 Wed Mar 15 03:14:04 2000    |       1 |  4000 |  4000000
 Wed Mar 15 02:14:05 2000    |       1 |  5000 |  5000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:00 1997    |       1 |     0 |        0
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Tue Jun 10 18:32:01 1997    |       2 |  1000 |  1000000
 Mon Feb 10 17:32:01 1997    |       1 |  1000 |  1000000
 Tue Feb 11 17:32:01 1997    |       1 |  1000 |  1000000
 Wed Feb 12 17:32:01 1997    |       1 |  1000 |  1000000
 Thu Feb 13 17:32:01 1997    |       1 |  1000 |  1000000
 Fri Feb 14 17:32:01 1997    |       1 |  1000 |  1000000
 Sat Feb 15 17:32:01 1997    |       1 |  1000 |  1000000
 Sun Feb 16 17:32:01 1997    |       1 |  1000 |  1000000
 Tue Feb 16 17:32:01 0097 BC |       1 |  1000 |  1000000
 Sat Feb 16 17:32:01 0097    |       1 |  1000 |  1000000
 Thu Feb 16 17:32:01 0597    |       1 |  1000 |  1000000
 Tue Feb 16 17:32:01 1097    |       1 |  1000 |  1000000
 Sat Feb 16 17:32:01 1697    |       1 |  1000 |  1000000
 Thu Feb 16 17:32:01 1797    |       1 |  1000 |  1000000
 Tue Feb 16 17:32:01 1897    |       1 |  1000 |  1000000
 Sun Feb 16 17:32:01 1997    |       1 |  1000 |  1000000
 Sat Feb 16 17:32:01 2097    |       1 |  1000 |  1000000
 Wed Feb 28 17:32:01 1996    |       1 |  1000 |  1000000
 Thu Feb 29 17:32:01 1996    |       1 |  1000 |  1000000
 Fri Mar 01 17:32:01 1996    |       1 |  1000 |  1000000
 Mon Dec 30 17:32:01 1996    |       4 |  1000 |  1000000
 Tue Dec 31 17:32:01 1996    |       4 |  1000 |  1000000
 Wed Jan 01 17:32:01 1997    |       1 |  1000 |  1000000
 Fri Feb 28 17:32:01 1997    |       1 |  1000 |  1000000
 Sat Mar 01 17:32:01 1997    |       1 |  1000 |  1000000
 Tue Dec 30 17:32:01 1997    |       4 |  1000 |  1000000
 Wed Dec 31 17:32:01 1997    |       4 |  1000 |  1000000
 Fri Dec 31 17:32:01 1999    |       4 |  1000 |  1000000
 Sat Jan 01 17:32:01 2000    |       1 |  1000 |  1000000
 Sun Dec 31 17:32:01 2000    |       4 |  1000 |  1000000
 Mon Jan 01 17:32:01 2001    |       1 |  1000 |  1000000
(65 rows)

SELECT d1 as "timestamp",
   date_part( 'isoyear', d1) AS isoyear, date_part( 'week', d1) AS week,
   date_part( 'isodow', d1) AS isodow, date_part( 'dow', d1) AS dow,
   date_part( 'doy', d1) AS doy
   FROM TIMESTAMP_TBL;
          timestamp          |  isoyear  | week | isodow | dow | doy 
-----------------------------+-----------+------+--------+-----+-----
 -infinity                   | -Infinity |      |        |     |    
 infinity                    |  Infinity |      |        |     |    
 Thu Jan 01 00:00:00 1970    |      1970 |    1 |      4 |   4 |   1
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:02 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01.4 1997  |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01.5 1997  |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01.6 1997  |      1997 |    7 |      1 |   1 |  41
 Thu Jan 02 00:00:00 1997    |      1997 |    1 |      4 |   4 |   2
 Thu Jan 02 03:04:05 1997    |      1997 |    1 |      4 |   4 |   2
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Tue Jun 10 17:32:01 1997    |      1997 |   24 |      2 |   2 | 161
 Sat Sep 22 18:19:20 2001    |      2001 |   38 |      6 |   6 | 265
 Wed Mar 15 08:14:01 2000    |      2000 |   11 |      3 |   3 |  75
 Wed Mar 15 13:14:02 2000    |      2000 |   11 |      3 |   3 |  75
 Wed Mar 15 12:14:03 2000    |      2000 |   11 |      3 |   3 |  75
 Wed Mar 15 03:14:04 2000    |      2000 |   11 |      3 |   3 |  75
 Wed Mar 15 02:14:05 2000    |      2000 |   11 |      3 |   3 |  75
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:00 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Tue Jun 10 18:32:01 1997    |      1997 |   24 |      2 |   2 | 161
 Mon Feb 10 17:32:01 1997    |      1997 |    7 |      1 |   1 |  41
 Tue Feb 11 17:32:01 1997    |      1997 |    7 |      2 |   2 |  42
 Wed Feb 12 17:32:01 1997    |      1997 |    7 |      3 |   3 |  43
 Thu Feb 13 17:32:01 1997    |      1997 |    7 |      4 |   4 |  44
 Fri Feb 14 17:32:01 1997    |      1997 |    7 |      5 |   5 |  45
 Sat Feb 15 17:32:01 1997    |      1997 |    7 |      6 |   6 |  46
 Sun Feb 16 17:32:01 1997    |      1997 |    7 |      7 |   0 |  47
 Tue Feb 16 17:32:01 0097 BC |       -97 |    7 |      2 |   2 |  47
 Sat Feb 16 17:32:01 0097    |        97 |    7 |      6 |   6 |  47
 Thu Feb 16 17:32:01 0597    |       597 |    7 |      4 |   4 |  47
 Tue Feb 16 17:32:01 1097    |      1097 |    7 |      2 |   2 |  47
 Sat Feb 16 17:32:01 1697    |      1697 |    7 |      6 |   6 |  47
 Thu Feb 16 17:32:01 1797    |      1797 |    7 |      4 |   4 |  47
 Tue Feb 16 17:32:01 1897    |      1897 |    7 |      2 |   2 |  47
 Sun Feb 16 17:32:01 1997    |      1997 |    7 |      7 |   0 |  47
 Sat Feb 16 17:32:01 2097    |      2097 |    7 |      6 |   6 |  47
 Wed Feb 28 17:32:01 1996    |      1996 |    9 |      3 |   3 |  59
 Thu Feb 29 17:32:01 1996    |      1996 |    9 |      4 |   4 |  60
 Fri Mar 01 17:32:01 1996    |      1996 |    9 |      5 |   5 |  61
 Mon Dec 30 17:32:01 1996    |      1997 |    1 |      1 |   1 | 365
 Tue Dec 31 17:32:01 1996    |      1997 |    1 |      2 |   2 | 366
 Wed Jan 01 17:32:01 1997    |      1997 |    1 |      3 |   3 |   1
 Fri Feb 28 17:32:01 1997    |      1997 |    9 |      5 |   5 |  59
 Sat Mar 01 17:32:01 1997    |      1997 |    9 |      6 |   6 |  60
 Tue Dec 30 17:32:01 1997    |      1998 |    1 |      2 |   2 | 364
 Wed Dec 31 17:32:01 1997    |      1998 |    1 |      3 |   3 | 365
 Fri Dec 31 17:32:01 1999    |      1999 |   52 |      5 |   5 | 365
 Sat Jan 01 17:32:01 2000    |      1999 |   52 |      6 |   6 |   1
 Sun Dec 31 17:32:01 2000    |      2000 |   52 |      7 |   0 | 366
 Mon Jan 01 17:32:01 2001    |      2001 |    1 |      1 |   1 |   1
(65 rows)

SELECT d1 as "timestamp",
   date_part( 'decade', d1) AS decade,
   date_part( 'century', d1) AS century,
   date_part( 'millennium', d1) AS millennium,
   round(date_part( 'julian', d1)) AS julian,
   date_part( 'epoch', d1) AS epoch
   FROM TIMESTAMP_TBL;
          timestamp          |  decade   |  century  | millennium |  julian   |    epoch     
-----------------------------+-----------+-----------+------------+-----------+--------------
 -infinity                   | -Infinity | -Infinity |  -Infinity | -Infinity |    -Infinity
 infinity                    |  Infinity |  Infinity |   Infinity |  Infinity |     Infinity
 Thu Jan 01 00:00:00 1970    |       197 |        20 |          2 |   2440588 |            0
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:02 1997    |       199 |        20 |          2 |   2450491 |    855595922
 Mon Feb 10 17:32:01.4 1997  |       199 |        20 |          2 |   2450491 |  855595921.4
 Mon Feb 10 17:32:01.5 1997  |       199 |        20 |          2 |   2450491 |  855595921.5
 Mon Feb 10 17:32:01.6 1997  |       199 |        20 |          2 |   2450491 |  855595921.6
 Thu Jan 02 00:00:00 1997    |       199 |        20 |          2 |   2450451 |    852163200
 Thu Jan 02 03:04:05 1997    |       199 |        20 |          2 |   2450451 |    852174245
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Tue Jun 10 17:32:01 1997    |       199 |        20 |          2 |   2450611 |    865963921
 Sat Sep 22 18:19:20 2001    |       200 |        21 |          3 |   2452176 |   1001182760
 Wed Mar 15 08:14:01 2000    |       200 |        20 |          2 |   2451619 |    953108041
 Wed Mar 15 13:14:02 2000    |       200 |        20 |          2 |   2451620 |    953126042
 Wed Mar 15 12:14:03 2000    |       200 |        20 |          2 |   2451620 |    953122443
 Wed Mar 15 03:14:04 2000    |       200 |        20 |          2 |   2451619 |    953090044
 Wed Mar 15 02:14:05 2000    |       200 |        20 |          2 |   2451619 |    953086445
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:00 1997    |       199 |        20 |          2 |   2450491 |    855595920
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Tue Jun 10 18:32:01 1997    |       199 |        20 |          2 |   2450611 |    865967521
 Mon Feb 10 17:32:01 1997    |       199 |        20 |          2 |   2450491 |    855595921
 Tue Feb 11 17:32:01 1997    |       199 |        20 |          2 |   2450492 |    855682321
 Wed Feb 12 17:32:01 1997    |       199 |        20 |          2 |   2450493 |    855768721
 Thu Feb 13 17:32:01 1997    |       199 |        20 |          2 |   2450494 |    855855121
 Fri Feb 14 17:32:01 1997    |       199 |        20 |          2 |   2450495 |    855941521
 Sat Feb 15 17:32:01 1997    |       199 |        20 |          2 |   2450496 |    856027921
 Sun Feb 16 17:32:01 1997    |       199 |        20 |          2 |   2450497 |    856114321
 Tue Feb 16 17:32:01 0097 BC |       -10 |        -1 |         -1 |   1686043 | -65192711279
 Sat Feb 16 17:32:01 0097    |         9 |         1 |          1 |   1756537 | -59102029679
 Thu Feb 16 17:32:01 0597    |        59 |         6 |          1 |   1939158 | -43323575279
 Tue Feb 16 17:32:01 1097    |       109 |        11 |          2 |   2121779 | -27545120879
 Sat Feb 16 17:32:01 1697    |       169 |        17 |          2 |   2340925 |  -8610906479
 Thu Feb 16 17:32:01 1797    |       179 |        18 |          2 |   2377449 |  -5455232879
 Tue Feb 16 17:32:01 1897    |       189 |        19 |          2 |   2413973 |  -2299559279
 Sun Feb 16 17:32:01 1997    |       199 |        20 |          2 |   2450497 |    856114321
 Sat Feb 16 17:32:01 2097    |       209 |        21 |          3 |   2487022 |   4011874321
 Wed Feb 28 17:32:01 1996    |       199 |        20 |          2 |   2450143 |    825528721
 Thu Feb 29 17:32:01 1996    |       199 |        20 |          2 |   2450144 |    825615121
 Fri Mar 01 17:32:01 1996    |       199 |        20 |          2 |   2450145 |    825701521
 Mon Dec 30 17:32:01 1996    |       199 |        20 |          2 |   2450449 |    851967121
 Tue Dec 31 17:32:01 1996    |       199 |        20 |          2 |   2450450 |    852053521
 Wed Jan 01 17:32:01 1997    |       199 |        20 |          2 |   2450451 |    852139921
 Fri Feb 28 17:32:01 1997    |       199 |        20 |          2 |   2450509 |    857151121
 Sat Mar 01 17:32:01 1997    |       199 |        20 |          2 |   2450510 |    857237521
 Tue Dec 30 17:32:01 1997    |       199 |        20 |          2 |   2450814 |    883503121
 Wed Dec 31 17:32:01 1997    |       199 |        20 |          2 |   2450815 |    883589521
 Fri Dec 31 17:32:01 1999    |       199 |        20 |          2 |   2451545 |    946661521
 Sat Jan 01 17:32:01 2000    |       200 |        20 |          2 |   2451546 |    946747921
 Sun Dec 31 17:32:01 2000    |       200 |        20 |          2 |   2451911 |    978283921
 Mon Jan 01 17:32:01 2001    |       200 |        21 |          3 |   2451912 |    978370321
(65 rows)

-- extract implementation is mostly the same as date_part, so only
-- test a few cases for additional coverage.
SELECT d1 as "timestamp",
   extract(microseconds from d1) AS microseconds,
   extract(milliseconds from d1) AS milliseconds,
   extract(seconds from d1) AS seconds,
   round(extract(julian from d1)) AS julian,
   extract(epoch from d1) AS epoch
   FROM TIMESTAMP_TBL;
          timestamp          | microseconds | milliseconds |  seconds  |  julian   |        epoch        
-----------------------------+--------------+--------------+-----------+-----------+---------------------
 -infinity                   |              |              |           | -Infinity |           -Infinity
 infinity                    |              |              |           |  Infinity |            Infinity
 Thu Jan 01 00:00:00 1970    |            0 |        0.000 |  0.000000 |   2440588 |            0.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:02 1997    |      2000000 |     2000.000 |  2.000000 |   2450491 |    855595922.000000
 Mon Feb 10 17:32:01.4 1997  |      1400000 |     1400.000 |  1.400000 |   2450491 |    855595921.400000
 Mon Feb 10 17:32:01.5 1997  |      1500000 |     1500.000 |  1.500000 |   2450491 |    855595921.500000
 Mon Feb 10 17:32:01.6 1997  |      1600000 |     1600.000 |  1.600000 |   2450491 |    855595921.600000
 Thu Jan 02 00:00:00 1997    |            0 |        0.000 |  0.000000 |   2450451 |    852163200.000000
 Thu Jan 02 03:04:05 1997    |      5000000 |     5000.000 |  5.000000 |   2450451 |    852174245.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Tue Jun 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450611 |    865963921.000000
 Sat Sep 22 18:19:20 2001    |     20000000 |    20000.000 | 20.000000 |   2452176 |   1001182760.000000
 Wed Mar 15 08:14:01 2000    |      1000000 |     1000.000 |  1.000000 |   2451619 |    953108041.000000
 Wed Mar 15 13:14:02 2000    |      2000000 |     2000.000 |  2.000000 |   2451620 |    953126042.000000
 Wed Mar 15 12:14:03 2000    |      3000000 |     3000.000 |  3.000000 |   2451620 |    953122443.000000
 Wed Mar 15 03:14:04 2000    |      4000000 |     4000.000 |  4.000000 |   2451619 |    953090044.000000
 Wed Mar 15 02:14:05 2000    |      5000000 |     5000.000 |  5.000000 |   2451619 |    953086445.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:00 1997    |            0 |        0.000 |  0.000000 |   2450491 |    855595920.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Tue Jun 10 18:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450611 |    865967521.000000
 Mon Feb 10 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450491 |    855595921.000000
 Tue Feb 11 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450492 |    855682321.000000
 Wed Feb 12 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450493 |    855768721.000000
 Thu Feb 13 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450494 |    855855121.000000
 Fri Feb 14 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450495 |    855941521.000000
 Sat Feb 15 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450496 |    856027921.000000
 Sun Feb 16 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450497 |    856114321.000000
 Tue Feb 16 17:32:01 0097 BC |      1000000 |     1000.000 |  1.000000 |   1686043 | -65192711279.000000
 Sat Feb 16 17:32:01 0097    |      1000000 |     1000.000 |  1.000000 |   1756537 | -59102029679.000000
 Thu Feb 16 17:32:01 0597    |      1000000 |     1000.000 |  1.000000 |   1939158 | -43323575279.000000
 Tue Feb 16 17:32:01 1097    |      1000000 |     1000.000 |  1.000000 |   2121779 | -27545120879.000000
 Sat Feb 16 17:32:01 1697    |      1000000 |     1000.000 |  1.000000 |   2340925 |  -8610906479.000000
 Thu Feb 16 17:32:01 1797    |      1000000 |     1000.000 |  1.000000 |   2377449 |  -5455232879.000000
 Tue Feb 16 17:32:01 1897    |      1000000 |     1000.000 |  1.000000 |   2413973 |  -2299559279.000000
 Sun Feb 16 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450497 |    856114321.000000
 Sat Feb 16 17:32:01 2097    |      1000000 |     1000.000 |  1.000000 |   2487022 |   4011874321.000000
 Wed Feb 28 17:32:01 1996    |      1000000 |     1000.000 |  1.000000 |   2450143 |    825528721.000000
 Thu Feb 29 17:32:01 1996    |      1000000 |     1000.000 |  1.000000 |   2450144 |    825615121.000000
 Fri Mar 01 17:32:01 1996    |      1000000 |     1000.000 |  1.000000 |   2450145 |    825701521.000000
 Mon Dec 30 17:32:01 1996    |      1000000 |     1000.000 |  1.000000 |   2450449 |    851967121.000000
 Tue Dec 31 17:32:01 1996    |      1000000 |     1000.000 |  1.000000 |   2450450 |    852053521.000000
 Wed Jan 01 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450451 |    852139921.000000
 Fri Feb 28 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450509 |    857151121.000000
 Sat Mar 01 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450510 |    857237521.000000
 Tue Dec 30 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450814 |    883503121.000000
 Wed Dec 31 17:32:01 1997    |      1000000 |     1000.000 |  1.000000 |   2450815 |    883589521.000000
 Fri Dec 31 17:32:01 1999    |      1000000 |     1000.000 |  1.000000 |   2451545 |    946661521.000000
 Sat Jan 01 17:32:01 2000    |      1000000 |     1000.000 |  1.000000 |   2451546 |    946747921.000000
 Sun Dec 31 17:32:01 2000    |      1000000 |     1000.000 |  1.000000 |   2451911 |    978283921.000000
 Mon Jan 01 17:32:01 2001    |      1000000 |     1000.000 |  1.000000 |   2451912 |    978370321.000000
(65 rows)

-- value near upper bound uses special case in code
SELECT date_part('epoch', '294270-01-01 00:00:00'::timestamp);
   date_part   
---------------
 9224097091200
(1 row)

SELECT extract(epoch from '294270-01-01 00:00:00'::timestamp);
       extract        
----------------------
 9224097091200.000000
(1 row)

-- another internal overflow test case
SELECT extract(epoch from '5000-01-01 00:00:00'::timestamp);
      extract       
--------------------
 95617584000.000000
(1 row)

-- TO_CHAR()
SELECT to_char(d1, 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon')
   FROM TIMESTAMP_TBL;
                                         to_char                                          
------------------------------------------------------------------------------------------
 
 
 THURSDAY  Thursday  thursday  THU Thu thu JANUARY   January   january   I    JAN Jan jan
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 THURSDAY  Thursday  thursday  THU Thu thu JANUARY   January   january   I    JAN Jan jan
 THURSDAY  Thursday  thursday  THU Thu thu JANUARY   January   january   I    JAN Jan jan
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 TUESDAY   Tuesday   tuesday   TUE Tue tue JUNE      June      june      VI   JUN Jun jun
 SATURDAY  Saturday  saturday  SAT Sat sat SEPTEMBER September september IX   SEP Sep sep
 WEDNESDAY Wednesday wednesday WED Wed wed MARCH     March     march     III  MAR Mar mar
 WEDNESDAY Wednesday wednesday WED Wed wed MARCH     March     march     III  MAR Mar mar
 WEDNESDAY Wednesday wednesday WED Wed wed MARCH     March     march     III  MAR Mar mar
 WEDNESDAY Wednesday wednesday WED Wed wed MARCH     March     march     III  MAR Mar mar
 WEDNESDAY Wednesday wednesday WED Wed wed MARCH     March     march     III  MAR Mar mar
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 TUESDAY   Tuesday   tuesday   TUE Tue tue JUNE      June      june      VI   JUN Jun jun
 MONDAY    Monday    monday    MON Mon mon FEBRUARY  February  february  II   FEB Feb feb
 TUESDAY   Tuesday   tuesday   TUE Tue tue FEBRUARY  February  february  II   FEB Feb feb
 WEDNESDAY Wednesday wednesday WED Wed wed FEBRUARY  February  february  II   FEB Feb feb
 THURSDAY  Thursday  thursday  THU Thu thu FEBRUARY  February  february  II   FEB Feb feb
 FRIDAY    Friday    friday    FRI Fri fri FEBRUARY  February  february  II   FEB Feb feb
 SATURDAY  Saturday  saturday  SAT Sat sat FEBRUARY  February  february  II   FEB Feb feb
 SUNDAY    Sunday    sunday    SUN Sun sun FEBRUARY  February  february  II   FEB Feb feb
 TUESDAY   Tuesday   tuesday   TUE Tue tue FEBRUARY  February  february  II   FEB Feb feb
 SATURDAY  Saturday  saturday  SAT Sat sat FEBRUARY  February  february  II   FEB Feb feb
 THURSDAY  Thursday  thursday  THU Thu thu FEBRUARY  February  february  II   FEB Feb feb
 TUESDAY   Tuesday   tuesday   TUE Tue tue FEBRUARY  February  february  II   FEB Feb feb
 SATURDAY  Saturday  saturday  SAT Sat sat FEBRUARY  February  february  II   FEB Feb feb
 THURSDAY  Thursday  thursday  THU Thu thu FEBRUARY  February  february  II   FEB Feb feb
 TUESDAY   Tuesday   tuesday   TUE Tue tue FEBRUARY  February  february  II   FEB Feb feb
 SUNDAY    Sunday    sunday    SUN Sun sun FEBRUARY  February  february  II   FEB Feb feb
 SATURDAY  Saturday  saturday  SAT Sat sat FEBRUARY  February  february  II   FEB Feb feb
 WEDNESDAY Wednesday wednesday WED Wed wed FEBRUARY  February  february  II   FEB Feb feb
 THURSDAY  Thursday  thursday  THU Thu thu FEBRUARY  February  february  II   FEB Feb feb
 FRIDAY    Friday    friday    FRI Fri fri MARCH     March     march     III  MAR Mar mar
 MONDAY    Monday    monday    MON Mon mon DECEMBER  December  december  XII  DEC Dec dec
 TUESDAY   Tuesday   tuesday   TUE Tue tue DECEMBER  December  december  XII  DEC Dec dec
 WEDNESDAY Wednesday wednesday WED Wed wed JANUARY   January   january   I    JAN Jan jan
 FRIDAY    Friday    friday    FRI Fri fri FEBRUARY  February  february  II   FEB Feb feb
 SATURDAY  Saturday  saturday  SAT Sat sat MARCH     March     march     III  MAR Mar mar
 TUESDAY   Tuesday   tuesday   TUE Tue tue DECEMBER  December  december  XII  DEC Dec dec
 WEDNESDAY Wednesday wednesday WED Wed wed DECEMBER  December  december  XII  DEC Dec dec
 FRIDAY    Friday    friday    FRI Fri fri DECEMBER  December  december  XII  DEC Dec dec
 SATURDAY  Saturday  saturday  SAT Sat sat JANUARY   January   january   I    JAN Jan jan
 SUNDAY    Sunday    sunday    SUN Sun sun DECEMBER  December  december  XII  DEC Dec dec
 MONDAY    Monday    monday    MON Mon mon JANUARY   January   january   I    JAN Jan jan
(65 rows)

SELECT to_char(d1, 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth FMRM')
   FROM TIMESTAMP_TBL;
                           to_char                            
--------------------------------------------------------------
 
 
 THURSDAY Thursday thursday JANUARY January january I
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 THURSDAY Thursday thursday JANUARY January january I
 THURSDAY Thursday thursday JANUARY January january I
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 TUESDAY Tuesday tuesday JUNE June june VI
 SATURDAY Saturday saturday SEPTEMBER September september IX
 WEDNESDAY Wednesday wednesday MARCH March march III
 WEDNESDAY Wednesday wednesday MARCH March march III
 WEDNESDAY Wednesday wednesday MARCH March march III
 WEDNESDAY Wednesday wednesday MARCH March march III
 WEDNESDAY Wednesday wednesday MARCH March march III
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 MONDAY Monday monday FEBRUARY February february II
 TUESDAY Tuesday tuesday JUNE June june VI
 MONDAY Monday monday FEBRUARY February february II
 TUESDAY Tuesday tuesday FEBRUARY February february II
 WEDNESDAY Wednesday wednesday FEBRUARY February february II
 THURSDAY Thursday thursday FEBRUARY February february II
 FRIDAY Friday friday FEBRUARY February february II
 SATURDAY Saturday saturday FEBRUARY February february II
 SUNDAY Sunday sunday FEBRUARY February february II
 TUESDAY Tuesday tuesday FEBRUARY February february II
 SATURDAY Saturday saturday FEBRUARY February february II
 THURSDAY Thursday thursday FEBRUARY February february II
 TUESDAY Tuesday tuesday FEBRUARY February february II
 SATURDAY Saturday saturday FEBRUARY February february II
 THURSDAY Thursday thursday FEBRUARY February february II
 TUESDAY Tuesday tuesday FEBRUARY February february II
 SUNDAY Sunday sunday FEBRUARY February february II
 SATURDAY Saturday saturday FEBRUARY February february II
 WEDNESDAY Wednesday wednesday FEBRUARY February february II
 THURSDAY Thursday thursday FEBRUARY February february II
 FRIDAY Friday friday MARCH March march III
 MONDAY Monday monday DECEMBER December december XII
 TUESDAY Tuesday tuesday DECEMBER December december XII
 WEDNESDAY Wednesday wednesday JANUARY January january I
 FRIDAY Friday friday FEBRUARY February february II
 SATURDAY Saturday saturday MARCH March march III
 TUESDAY Tuesday tuesday DECEMBER December december XII
 WEDNESDAY Wednesday wednesday DECEMBER December december XII
 FRIDAY Friday friday DECEMBER December december XII
 SATURDAY Saturday saturday JANUARY January january I
 SUNDAY Sunday sunday DECEMBER December december XII
 MONDAY Monday monday JANUARY January january I
(65 rows)

SELECT to_char(d1, 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J')
   FROM TIMESTAMP_TBL;
                     to_char                      
--------------------------------------------------
 
 
 1,970 1970 970 70 0 20 1 01 01 001 01 5 2440588
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 01 01 002 02 5 2450451
 1,997 1997 997 97 7 20 1 01 01 002 02 5 2450451
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 2 06 23 161 10 3 2450610
 2,001 2001 001 01 1 21 3 09 38 265 22 7 2452175
 2,000 2000 000 00 0 20 1 03 11 075 15 4 2451619
 2,000 2000 000 00 0 20 1 03 11 075 15 4 2451619
 2,000 2000 000 00 0 20 1 03 11 075 15 4 2451619
 2,000 2000 000 00 0 20 1 03 11 075 15 4 2451619
 2,000 2000 000 00 0 20 1 03 11 075 15 4 2451619
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 2 06 23 161 10 3 2450610
 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490
 1,997 1997 997 97 7 20 1 02 06 042 11 3 2450491
 1,997 1997 997 97 7 20 1 02 07 043 12 4 2450492
 1,997 1997 997 97 7 20 1 02 07 044 13 5 2450493
 1,997 1997 997 97 7 20 1 02 07 045 14 6 2450494
 1,997 1997 997 97 7 20 1 02 07 046 15 7 2450495
 1,997 1997 997 97 7 20 1 02 07 047 16 1 2450496
 0,097 0097 097 97 7 -01 1 02 07 047 16 3 1686042
 0,097 0097 097 97 7 01 1 02 07 047 16 7 1756536
 0,597 0597 597 97 7 06 1 02 07 047 16 5 1939157
 1,097 1097 097 97 7 11 1 02 07 047 16 3 2121778
 1,697 1697 697 97 7 17 1 02 07 047 16 7 2340924
 1,797 1797 797 97 7 18 1 02 07 047 16 5 2377448
 1,897 1897 897 97 7 19 1 02 07 047 16 3 2413972
 1,997 1997 997 97 7 20 1 02 07 047 16 1 2450496
 2,097 2097 097 97 7 21 1 02 07 047 16 7 2487021
 1,996 1996 996 96 6 20 1 02 09 059 28 4 2450142
 1,996 1996 996 96 6 20 1 02 09 060 29 5 2450143
 1,996 1996 996 96 6 20 1 03 09 061 01 6 2450144
 1,996 1996 996 96 6 20 4 12 53 365 30 2 2450448
 1,996 1996 996 96 6 20 4 12 53 366 31 3 2450449
 1,997 1997 997 97 7 20 1 01 01 001 01 4 2450450
 1,997 1997 997 97 7 20 1 02 09 059 28 6 2450508
 1,997 1997 997 97 7 20 1 03 09 060 01 7 2450509
 1,997 1997 997 97 7 20 4 12 52 364 30 3 2450813
 1,997 1997 997 97 7 20 4 12 53 365 31 4 2450814
 1,999 1999 999 99 9 20 4 12 53 365 31 6 2451544
 2,000 2000 000 00 0 20 1 01 01 001 01 7 2451545
 2,000 2000 000 00 0 20 4 12 53 366 31 1 2451910
 2,001 2001 001 01 1 21 1 01 01 001 01 2 2451911
(65 rows)

SELECT to_char(d1, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMD FMJ')
   FROM TIMESTAMP_TBL;
                     to_char                     
-------------------------------------------------
 
 
 1,970 1970 970 70 0 20 1 1 1 1 1 5 2440588
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 1 1 2 2 5 2450451
 1,997 1997 997 97 7 20 1 1 1 2 2 5 2450451
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 2 6 23 161 10 3 2450610
 2,001 2001 1 1 1 21 3 9 38 265 22 7 2452175
 2,000 2000 0 0 0 20 1 3 11 75 15 4 2451619
 2,000 2000 0 0 0 20 1 3 11 75 15 4 2451619
 2,000 2000 0 0 0 20 1 3 11 75 15 4 2451619
 2,000 2000 0 0 0 20 1 3 11 75 15 4 2451619
 2,000 2000 0 0 0 20 1 3 11 75 15 4 2451619
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 2 6 23 161 10 3 2450610
 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490
 1,997 1997 997 97 7 20 1 2 6 42 11 3 2450491
 1,997 1997 997 97 7 20 1 2 7 43 12 4 2450492
 1,997 1997 997 97 7 20 1 2 7 44 13 5 2450493
 1,997 1997 997 97 7 20 1 2 7 45 14 6 2450494
 1,997 1997 997 97 7 20 1 2 7 46 15 7 2450495
 1,997 1997 997 97 7 20 1 2 7 47 16 1 2450496
 0,097 97 97 97 7 -1 1 2 7 47 16 3 1686042
 0,097 97 97 97 7 1 1 2 7 47 16 7 1756536
 0,597 597 597 97 7 6 1 2 7 47 16 5 1939157
 1,097 1097 97 97 7 11 1 2 7 47 16 3 2121778
 1,697 1697 697 97 7 17 1 2 7 47 16 7 2340924
 1,797 1797 797 97 7 18 1 2 7 47 16 5 2377448
 1,897 1897 897 97 7 19 1 2 7 47 16 3 2413972
 1,997 1997 997 97 7 20 1 2 7 47 16 1 2450496
 2,097 2097 97 97 7 21 1 2 7 47 16 7 2487021
 1,996 1996 996 96 6 20 1 2 9 59 28 4 2450142
 1,996 1996 996 96 6 20 1 2 9 60 29 5 2450143
 1,996 1996 996 96 6 20 1 3 9 61 1 6 2450144
 1,996 1996 996 96 6 20 4 12 53 365 30 2 2450448
 1,996 1996 996 96 6 20 4 12 53 366 31 3 2450449
 1,997 1997 997 97 7 20 1 1 1 1 1 4 2450450
 1,997 1997 997 97 7 20 1 2 9 59 28 6 2450508
 1,997 1997 997 97 7 20 1 3 9 60 1 7 2450509
 1,997 1997 997 97 7 20 4 12 52 364 30 3 2450813
 1,997 1997 997 97 7 20 4 12 53 365 31 4 2450814
 1,999 1999 999 99 9 20 4 12 53 365 31 6 2451544
 2,000 2000 0 0 0 20 1 1 1 1 1 7 2451545
 2,000 2000 0 0 0 20 4 12 53 366 31 1 2451910
 2,001 2001 1 1 1 21 1 1 1 1 1 2 2451911
(65 rows)

SELECT to_char(d1, 'HH HH12 HH24 MI SS SSSS')
   FROM TIMESTAMP_TBL;
       to_char        
----------------------
 
 
 12 12 00 00 00 0
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 02 63122
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 12 12 00 00 00 0
 03 03 03 04 05 11045
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 06 06 18 19 20 65960
 08 08 08 14 01 29641
 01 01 13 14 02 47642
 12 12 12 14 03 44043
 03 03 03 14 04 11644
 02 02 02 14 05 8045
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 00 63120
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 06 06 18 32 01 66721
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
 05 05 17 32 01 63121
(65 rows)

SELECT to_char(d1, E'"HH:MI:SS is" HH:MI:SS "\\"text between quote marks\\""')
   FROM TIMESTAMP_TBL;
                     to_char                     
-------------------------------------------------
 
 
 HH:MI:SS is 12:00:00 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:02 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 12:00:00 "text between quote marks"
 HH:MI:SS is 03:04:05 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 06:19:20 "text between quote marks"
 HH:MI:SS is 08:14:01 "text between quote marks"
 HH:MI:SS is 01:14:02 "text between quote marks"
 HH:MI:SS is 12:14:03 "text between quote marks"
 HH:MI:SS is 03:14:04 "text between quote marks"
 HH:MI:SS is 02:14:05 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:00 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 06:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
 HH:MI:SS is 05:32:01 "text between quote marks"
(65 rows)

SELECT to_char(d1, 'HH24--text--MI--text--SS')
   FROM TIMESTAMP_TBL;
        to_char         
------------------------
 
 
 00--text--00--text--00
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--02
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 00--text--00--text--00
 03--text--04--text--05
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 18--text--19--text--20
 08--text--14--text--01
 13--text--14--text--02
 12--text--14--text--03
 03--text--14--text--04
 02--text--14--text--05
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--00
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 18--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
 17--text--32--text--01
(65 rows)

SELECT to_char(d1, 'YYYYTH YYYYth Jth')
   FROM TIMESTAMP_TBL;
         to_char         
-------------------------
 
 
 1970TH 1970th 2440588th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450451st
 1997TH 1997th 2450451st
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450610th
 2001ST 2001st 2452175th
 2000TH 2000th 2451619th
 2000TH 2000th 2451619th
 2000TH 2000th 2451619th
 2000TH 2000th 2451619th
 2000TH 2000th 2451619th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450490th
 1997TH 1997th 2450610th
 1997TH 1997th 2450490th
 1997TH 1997th 2450491st
 1997TH 1997th 2450492nd
 1997TH 1997th 2450493rd
 1997TH 1997th 2450494th
 1997TH 1997th 2450495th
 1997TH 1997th 2450496th
 0097TH 0097th 1686042nd
 0097TH 0097th 1756536th
 0597TH 0597th 1939157th
 1097TH 1097th 2121778th
 1697TH 1697th 2340924th
 1797TH 1797th 2377448th
 1897TH 1897th 2413972nd
 1997TH 1997th 2450496th
 2097TH 2097th 2487021st
 1996TH 1996th 2450142nd
 1996TH 1996th 2450143rd
 1996TH 1996th 2450144th
 1996TH 1996th 2450448th
 1996TH 1996th 2450449th
 1997TH 1997th 2450450th
 1997TH 1997th 2450508th
 1997TH 1997th 2450509th
 1997TH 1997th 2450813th
 1997TH 1997th 2450814th
 1999TH 1999th 2451544th
 2000TH 2000th 2451545th
 2000TH 2000th 2451910th
 2001ST 2001st 2451911th
(65 rows)

SELECT to_char(d1, 'YYYY A.D. YYYY a.d. YYYY bc HH:MI:SS P.M. HH:MI:SS p.m. HH:MI:SS pm')
   FROM TIMESTAMP_TBL;
                               to_char                               
---------------------------------------------------------------------
 
 
 1970 A.D. 1970 a.d. 1970 ad 12:00:00 A.M. 12:00:00 a.m. 12:00:00 am
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:02 P.M. 05:32:02 p.m. 05:32:02 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 12:00:00 A.M. 12:00:00 a.m. 12:00:00 am
 1997 A.D. 1997 a.d. 1997 ad 03:04:05 A.M. 03:04:05 a.m. 03:04:05 am
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 2001 A.D. 2001 a.d. 2001 ad 06:19:20 P.M. 06:19:20 p.m. 06:19:20 pm
 2000 A.D. 2000 a.d. 2000 ad 08:14:01 A.M. 08:14:01 a.m. 08:14:01 am
 2000 A.D. 2000 a.d. 2000 ad 01:14:02 P.M. 01:14:02 p.m. 01:14:02 pm
 2000 A.D. 2000 a.d. 2000 ad 12:14:03 P.M. 12:14:03 p.m. 12:14:03 pm
 2000 A.D. 2000 a.d. 2000 ad 03:14:04 A.M. 03:14:04 a.m. 03:14:04 am
 2000 A.D. 2000 a.d. 2000 ad 02:14:05 A.M. 02:14:05 a.m. 02:14:05 am
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:00 P.M. 05:32:00 p.m. 05:32:00 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 06:32:01 P.M. 06:32:01 p.m. 06:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 0097 B.C. 0097 b.c. 0097 bc 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 0097 A.D. 0097 a.d. 0097 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 0597 A.D. 0597 a.d. 0597 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1097 A.D. 1097 a.d. 1097 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1697 A.D. 1697 a.d. 1697 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1797 A.D. 1797 a.d. 1797 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1897 A.D. 1897 a.d. 1897 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 2097 A.D. 2097 a.d. 2097 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1996 A.D. 1996 a.d. 1996 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1996 A.D. 1996 a.d. 1996 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1996 A.D. 1996 a.d. 1996 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1996 A.D. 1996 a.d. 1996 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1996 A.D. 1996 a.d. 1996 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 1999 A.D. 1999 a.d. 1999 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 2000 A.D. 2000 a.d. 2000 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 2000 A.D. 2000 a.d. 2000 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
 2001 A.D. 2001 a.d. 2001 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm
(65 rows)

SELECT to_char(d1, 'IYYY IYY IY I IW IDDD ID')
   FROM TIMESTAMP_TBL;
        to_char         
------------------------
 
 
 1970 970 70 0 01 004 4
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 01 004 4
 1997 997 97 7 01 004 4
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 24 163 2
 2001 001 01 1 38 265 6
 2000 000 00 0 11 073 3
 2000 000 00 0 11 073 3
 2000 000 00 0 11 073 3
 2000 000 00 0 11 073 3
 2000 000 00 0 11 073 3
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 07 043 1
 1997 997 97 7 24 163 2
 1997 997 97 7 07 043 1
 1997 997 97 7 07 044 2
 1997 997 97 7 07 045 3
 1997 997 97 7 07 046 4
 1997 997 97 7 07 047 5
 1997 997 97 7 07 048 6
 1997 997 97 7 07 049 7
 0097 097 97 7 07 044 2
 0097 097 97 7 07 048 6
 0597 597 97 7 07 046 4
 1097 097 97 7 07 044 2
 1697 697 97 7 07 048 6
 1797 797 97 7 07 046 4
 1897 897 97 7 07 044 2
 1997 997 97 7 07 049 7
 2097 097 97 7 07 048 6
 1996 996 96 6 09 059 3
 1996 996 96 6 09 060 4
 1996 996 96 6 09 061 5
 1997 997 97 7 01 001 1
 1997 997 97 7 01 002 2
 1997 997 97 7 01 003 3
 1997 997 97 7 09 061 5
 1997 997 97 7 09 062 6
 1998 998 98 8 01 002 2
 1998 998 98 8 01 003 3
 1999 999 99 9 52 362 5
 1999 999 99 9 52 363 6
 2000 000 00 0 52 364 7
 2001 001 01 1 01 001 1
(65 rows)

SELECT to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID')
   FROM TIMESTAMP_TBL;
        to_char         
------------------------
 
 
 1970 970 70 0 1 4 4
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 1 4 4
 1997 997 97 7 1 4 4
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 24 163 2
 2001 1 1 1 38 265 6
 2000 0 0 0 11 73 3
 2000 0 0 0 11 73 3
 2000 0 0 0 11 73 3
 2000 0 0 0 11 73 3
 2000 0 0 0 11 73 3
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 7 43 1
 1997 997 97 7 24 163 2
 1997 997 97 7 7 43 1
 1997 997 97 7 7 44 2
 1997 997 97 7 7 45 3
 1997 997 97 7 7 46 4
 1997 997 97 7 7 47 5
 1997 997 97 7 7 48 6
 1997 997 97 7 7 49 7
 97 97 97 7 7 44 2
 97 97 97 7 7 48 6
 597 597 97 7 7 46 4
 1097 97 97 7 7 44 2
 1697 697 97 7 7 48 6
 1797 797 97 7 7 46 4
 1897 897 97 7 7 44 2
 1997 997 97 7 7 49 7
 2097 97 97 7 7 48 6
 1996 996 96 6 9 59 3
 1996 996 96 6 9 60 4
 1996 996 96 6 9 61 5
 1997 997 97 7 1 1 1
 1997 997 97 7 1 2 2
 1997 997 97 7 1 3 3
 1997 997 97 7 9 61 5
 1997 997 97 7 9 62 6
 1998 998 98 8 1 2 2
 1998 998 98 8 1 3 3
 1999 999 99 9 52 362 5
 1999 999 99 9 52 363 6
 2000 0 0 0 52 364 7
 2001 1 1 1 1 1 1
(65 rows)

SELECT to_char(d, 'FF1 FF2 FF3 FF4 FF5 FF6  ff1 ff2 ff3 ff4 ff5 ff6  MS US')
   FROM (VALUES
       ('2018-11-02 12:34:56'::timestamp),
       ('2018-11-02 12:34:56.78'),
       ('2018-11-02 12:34:56.78901'),
       ('2018-11-02 12:34:56.78901234')
   ) d(d);
                              to_char                               
--------------------------------------------------------------------
 0 00 000 0000 00000 000000  0 00 000 0000 00000 000000  000 000000
 7 78 780 7800 78000 780000  7 78 780 7800 78000 780000  780 780000
 7 78 789 7890 78901 789010  7 78 789 7890 78901 789010  789 789010
 7 78 789 7890 78901 789012  7 78 789 7890 78901 789012  789 789012
(4 rows)

-- Roman months, with upper and lower case.
SELECT i,
       to_char(i * interval '1mon', 'rm'),
       to_char(i * interval '1mon', 'RM')
    FROM generate_series(-13, 13) i;
  i  | to_char | to_char 
-----+---------+---------
 -13 | xii     | XII 
 -12 | i       | I   
 -11 | ii      | II  
 -10 | iii     | III 
  -9 | iv      | IV  
  -8 | v       | V   
  -7 | vi      | VI  
  -6 | vii     | VII 
  -5 | viii    | VIII
  -4 | ix      | IX  
  -3 | x       | X   
  -2 | xi      | XI  
  -1 | xii     | XII 
   0 |         | 
   1 | i       | I   
   2 | ii      | II  
   3 | iii     | III 
   4 | iv      | IV  
   5 | v       | V   
   6 | vi      | VI  
   7 | vii     | VII 
   8 | viii    | VIII
   9 | ix      | IX  
  10 | x       | X   
  11 | xi      | XI  
  12 | xii     | XII 
  13 | i       | I   
(27 rows)

-- timestamp numeric fields constructor
SELECT make_timestamp(2014, 12, 28, 6, 30, 45.887);
        make_timestamp        
------------------------------
 Sun Dec 28 06:30:45.887 2014
(1 row)

SELECT make_timestamp(-44, 3, 15, 12, 30, 15);
       make_timestamp        
-----------------------------
 Fri Mar 15 12:30:15 0044 BC
(1 row)

-- should fail
select make_timestamp(0, 7, 15, 12, 30, 15);
ERROR:  date field value out of range: 0-07-15
-- generate_series for timestamp
select * from generate_series('2020-01-01 00:00'::timestamp,
                              '2020-01-02 03:00'::timestamp,
                              '1 hour'::interval);
     generate_series      
--------------------------
 Wed Jan 01 00:00:00 2020
 Wed Jan 01 01:00:00 2020
 Wed Jan 01 02:00:00 2020
 Wed Jan 01 03:00:00 2020
 Wed Jan 01 04:00:00 2020
 Wed Jan 01 05:00:00 2020
 Wed Jan 01 06:00:00 2020
 Wed Jan 01 07:00:00 2020
 Wed Jan 01 08:00:00 2020
 Wed Jan 01 09:00:00 2020
 Wed Jan 01 10:00:00 2020
 Wed Jan 01 11:00:00 2020
 Wed Jan 01 12:00:00 2020
 Wed Jan 01 13:00:00 2020
 Wed Jan 01 14:00:00 2020
 Wed Jan 01 15:00:00 2020
 Wed Jan 01 16:00:00 2020
 Wed Jan 01 17:00:00 2020
 Wed Jan 01 18:00:00 2020
 Wed Jan 01 19:00:00 2020
 Wed Jan 01 20:00:00 2020
 Wed Jan 01 21:00:00 2020
 Wed Jan 01 22:00:00 2020
 Wed Jan 01 23:00:00 2020
 Thu Jan 02 00:00:00 2020
 Thu Jan 02 01:00:00 2020
 Thu Jan 02 02:00:00 2020
 Thu Jan 02 03:00:00 2020
(28 rows)

-- the LIMIT should allow this to terminate in a reasonable amount of time
-- (but that unfortunately doesn't work yet for SELECT * FROM ...)
select generate_series('2022-01-01 00:00'::timestamp,
                       'infinity'::timestamp,
                       '1 month'::interval) limit 10;
     generate_series      
--------------------------
 Sat Jan 01 00:00:00 2022
 Tue Feb 01 00:00:00 2022
 Tue Mar 01 00:00:00 2022
 Fri Apr 01 00:00:00 2022
 Sun May 01 00:00:00 2022
 Wed Jun 01 00:00:00 2022
 Fri Jul 01 00:00:00 2022
 Mon Aug 01 00:00:00 2022
 Thu Sep 01 00:00:00 2022
 Sat Oct 01 00:00:00 2022
(10 rows)

-- errors
select * from generate_series('2020-01-01 00:00'::timestamp,
                              '2020-01-02 03:00'::timestamp,
                              '0 hour'::interval);
ERROR:  step size cannot equal zero