4 CREATE TABLE DATE_TBL (f1 date);
5 INSERT INTO DATE_TBL VALUES ('1957-04-09');
6 INSERT INTO DATE_TBL VALUES ('1957-06-13');
7 INSERT INTO DATE_TBL VALUES ('1996-02-28');
8 INSERT INTO DATE_TBL VALUES ('1996-02-29');
9 INSERT INTO DATE_TBL VALUES ('1996-03-01');
10 INSERT INTO DATE_TBL VALUES ('1996-03-02');
11 INSERT INTO DATE_TBL VALUES ('1997-02-28');
12 INSERT INTO DATE_TBL VALUES ('1997-02-29');
13 ERROR: date/time field value out of range: "1997-02-29"
14 LINE 1: INSERT INTO DATE_TBL VALUES ('1997-02-29');
16 INSERT INTO DATE_TBL VALUES ('1997-03-01');
17 INSERT INTO DATE_TBL VALUES ('1997-03-02');
18 INSERT INTO DATE_TBL VALUES ('2000-04-01');
19 INSERT INTO DATE_TBL VALUES ('2000-04-02');
20 INSERT INTO DATE_TBL VALUES ('2000-04-03');
21 INSERT INTO DATE_TBL VALUES ('2038-04-08');
22 INSERT INTO DATE_TBL VALUES ('2039-04-09');
23 INSERT INTO DATE_TBL VALUES ('2040-04-10');
24 INSERT INTO DATE_TBL VALUES ('2040-04-10 BC');
25 SELECT f1 FROM DATE_TBL;
46 SELECT f1 FROM DATE_TBL WHERE f1 < '2000-01-01';
61 SELECT f1 FROM DATE_TBL
62 WHERE f1 BETWEEN '2000-01-01' AND '2001-01-01';
71 -- Check all the documented input formats
73 SET datestyle TO iso; -- display results in ISO
75 SELECT date 'January 8, 1999';
81 SELECT date '1999-01-08';
87 SELECT date '1999-01-18';
93 SELECT date '1/8/1999';
94 ERROR: date/time field value out of range: "1/8/1999"
95 LINE 1: SELECT date '1/8/1999';
97 HINT: Perhaps you need a different "datestyle" setting.
98 SELECT date '1/18/1999';
99 ERROR: date/time field value out of range: "1/18/1999"
100 LINE 1: SELECT date '1/18/1999';
102 HINT: Perhaps you need a different "datestyle" setting.
103 SELECT date '18/1/1999';
104 ERROR: date/time field value out of range: "18/1/1999"
105 LINE 1: SELECT date '18/1/1999';
107 HINT: Perhaps you need a different "datestyle" setting.
108 SELECT date '01/02/03';
114 SELECT date '19990108';
120 SELECT date '990108';
126 SELECT date '1999.008';
132 SELECT date 'J2451187';
138 SELECT date 'January 8, 99 BC';
139 ERROR: date/time field value out of range: "January 8, 99 BC"
140 LINE 1: SELECT date 'January 8, 99 BC';
142 HINT: Perhaps you need a different "datestyle" setting.
143 SELECT date '99-Jan-08';
149 SELECT date '1999-Jan-08';
155 SELECT date '08-Jan-99';
156 ERROR: date/time field value out of range: "08-Jan-99"
157 LINE 1: SELECT date '08-Jan-99';
159 HINT: Perhaps you need a different "datestyle" setting.
160 SELECT date '08-Jan-1999';
166 SELECT date 'Jan-08-99';
167 ERROR: date/time field value out of range: "Jan-08-99"
168 LINE 1: SELECT date 'Jan-08-99';
170 HINT: Perhaps you need a different "datestyle" setting.
171 SELECT date 'Jan-08-1999';
177 SELECT date '99-08-Jan';
178 ERROR: invalid input syntax for type date: "99-08-Jan"
179 LINE 1: SELECT date '99-08-Jan';
181 SELECT date '1999-08-Jan';
182 ERROR: invalid input syntax for type date: "1999-08-Jan"
183 LINE 1: SELECT date '1999-08-Jan';
185 SELECT date '99 Jan 08';
191 SELECT date '1999 Jan 08';
197 SELECT date '08 Jan 99';
198 ERROR: date/time field value out of range: "08 Jan 99"
199 LINE 1: SELECT date '08 Jan 99';
201 HINT: Perhaps you need a different "datestyle" setting.
202 SELECT date '08 Jan 1999';
208 SELECT date 'Jan 08 99';
209 ERROR: date/time field value out of range: "Jan 08 99"
210 LINE 1: SELECT date 'Jan 08 99';
212 HINT: Perhaps you need a different "datestyle" setting.
213 SELECT date 'Jan 08 1999';
219 SELECT date '99 08 Jan';
225 SELECT date '1999 08 Jan';
231 SELECT date '99-01-08';
237 SELECT date '1999-01-08';
243 SELECT date '08-01-99';
244 ERROR: date/time field value out of range: "08-01-99"
245 LINE 1: SELECT date '08-01-99';
247 HINT: Perhaps you need a different "datestyle" setting.
248 SELECT date '08-01-1999';
249 ERROR: date/time field value out of range: "08-01-1999"
250 LINE 1: SELECT date '08-01-1999';
252 HINT: Perhaps you need a different "datestyle" setting.
253 SELECT date '01-08-99';
254 ERROR: date/time field value out of range: "01-08-99"
255 LINE 1: SELECT date '01-08-99';
257 HINT: Perhaps you need a different "datestyle" setting.
258 SELECT date '01-08-1999';
259 ERROR: date/time field value out of range: "01-08-1999"
260 LINE 1: SELECT date '01-08-1999';
262 HINT: Perhaps you need a different "datestyle" setting.
263 SELECT date '99-08-01';
269 SELECT date '1999-08-01';
275 SELECT date '99 01 08';
281 SELECT date '1999 01 08';
287 SELECT date '08 01 99';
288 ERROR: date/time field value out of range: "08 01 99"
289 LINE 1: SELECT date '08 01 99';
291 HINT: Perhaps you need a different "datestyle" setting.
292 SELECT date '08 01 1999';
293 ERROR: date/time field value out of range: "08 01 1999"
294 LINE 1: SELECT date '08 01 1999';
296 HINT: Perhaps you need a different "datestyle" setting.
297 SELECT date '01 08 99';
298 ERROR: date/time field value out of range: "01 08 99"
299 LINE 1: SELECT date '01 08 99';
301 HINT: Perhaps you need a different "datestyle" setting.
302 SELECT date '01 08 1999';
303 ERROR: date/time field value out of range: "01 08 1999"
304 LINE 1: SELECT date '01 08 1999';
306 HINT: Perhaps you need a different "datestyle" setting.
307 SELECT date '99 08 01';
313 SELECT date '1999 08 01';
319 SET datestyle TO dmy;
320 SELECT date 'January 8, 1999';
326 SELECT date '1999-01-08';
332 SELECT date '1999-01-18';
338 SELECT date '1/8/1999';
344 SELECT date '1/18/1999';
345 ERROR: date/time field value out of range: "1/18/1999"
346 LINE 1: SELECT date '1/18/1999';
348 HINT: Perhaps you need a different "datestyle" setting.
349 SELECT date '18/1/1999';
355 SELECT date '01/02/03';
361 SELECT date '19990108';
367 SELECT date '990108';
373 SELECT date '1999.008';
379 SELECT date 'J2451187';
385 SELECT date 'January 8, 99 BC';
391 SELECT date '99-Jan-08';
392 ERROR: date/time field value out of range: "99-Jan-08"
393 LINE 1: SELECT date '99-Jan-08';
395 HINT: Perhaps you need a different "datestyle" setting.
396 SELECT date '1999-Jan-08';
402 SELECT date '08-Jan-99';
408 SELECT date '08-Jan-1999';
414 SELECT date 'Jan-08-99';
420 SELECT date 'Jan-08-1999';
426 SELECT date '99-08-Jan';
427 ERROR: invalid input syntax for type date: "99-08-Jan"
428 LINE 1: SELECT date '99-08-Jan';
430 SELECT date '1999-08-Jan';
431 ERROR: invalid input syntax for type date: "1999-08-Jan"
432 LINE 1: SELECT date '1999-08-Jan';
434 SELECT date '99 Jan 08';
435 ERROR: date/time field value out of range: "99 Jan 08"
436 LINE 1: SELECT date '99 Jan 08';
438 HINT: Perhaps you need a different "datestyle" setting.
439 SELECT date '1999 Jan 08';
445 SELECT date '08 Jan 99';
451 SELECT date '08 Jan 1999';
457 SELECT date 'Jan 08 99';
463 SELECT date 'Jan 08 1999';
469 SELECT date '99 08 Jan';
470 ERROR: invalid input syntax for type date: "99 08 Jan"
471 LINE 1: SELECT date '99 08 Jan';
473 SELECT date '1999 08 Jan';
479 SELECT date '99-01-08';
480 ERROR: date/time field value out of range: "99-01-08"
481 LINE 1: SELECT date '99-01-08';
483 HINT: Perhaps you need a different "datestyle" setting.
484 SELECT date '1999-01-08';
490 SELECT date '08-01-99';
496 SELECT date '08-01-1999';
502 SELECT date '01-08-99';
508 SELECT date '01-08-1999';
514 SELECT date '99-08-01';
515 ERROR: date/time field value out of range: "99-08-01"
516 LINE 1: SELECT date '99-08-01';
518 HINT: Perhaps you need a different "datestyle" setting.
519 SELECT date '1999-08-01';
525 SELECT date '99 01 08';
526 ERROR: date/time field value out of range: "99 01 08"
527 LINE 1: SELECT date '99 01 08';
529 HINT: Perhaps you need a different "datestyle" setting.
530 SELECT date '1999 01 08';
536 SELECT date '08 01 99';
542 SELECT date '08 01 1999';
548 SELECT date '01 08 99';
554 SELECT date '01 08 1999';
560 SELECT date '99 08 01';
561 ERROR: date/time field value out of range: "99 08 01"
562 LINE 1: SELECT date '99 08 01';
564 HINT: Perhaps you need a different "datestyle" setting.
565 SELECT date '1999 08 01';
571 SET datestyle TO mdy;
572 SELECT date 'January 8, 1999';
578 SELECT date '1999-01-08';
584 SELECT date '1999-01-18';
590 SELECT date '1/8/1999';
596 SELECT date '1/18/1999';
602 SELECT date '18/1/1999';
603 ERROR: date/time field value out of range: "18/1/1999"
604 LINE 1: SELECT date '18/1/1999';
606 HINT: Perhaps you need a different "datestyle" setting.
607 SELECT date '01/02/03';
613 SELECT date '19990108';
619 SELECT date '990108';
625 SELECT date '1999.008';
631 SELECT date 'J2451187';
637 SELECT date 'January 8, 99 BC';
643 SELECT date '99-Jan-08';
644 ERROR: date/time field value out of range: "99-Jan-08"
645 LINE 1: SELECT date '99-Jan-08';
647 HINT: Perhaps you need a different "datestyle" setting.
648 SELECT date '1999-Jan-08';
654 SELECT date '08-Jan-99';
660 SELECT date '08-Jan-1999';
666 SELECT date 'Jan-08-99';
672 SELECT date 'Jan-08-1999';
678 SELECT date '99-08-Jan';
679 ERROR: invalid input syntax for type date: "99-08-Jan"
680 LINE 1: SELECT date '99-08-Jan';
682 SELECT date '1999-08-Jan';
683 ERROR: invalid input syntax for type date: "1999-08-Jan"
684 LINE 1: SELECT date '1999-08-Jan';
686 SELECT date '99 Jan 08';
687 ERROR: invalid input syntax for type date: "99 Jan 08"
688 LINE 1: SELECT date '99 Jan 08';
690 SELECT date '1999 Jan 08';
696 SELECT date '08 Jan 99';
702 SELECT date '08 Jan 1999';
708 SELECT date 'Jan 08 99';
714 SELECT date 'Jan 08 1999';
720 SELECT date '99 08 Jan';
721 ERROR: invalid input syntax for type date: "99 08 Jan"
722 LINE 1: SELECT date '99 08 Jan';
724 SELECT date '1999 08 Jan';
730 SELECT date '99-01-08';
731 ERROR: date/time field value out of range: "99-01-08"
732 LINE 1: SELECT date '99-01-08';
734 HINT: Perhaps you need a different "datestyle" setting.
735 SELECT date '1999-01-08';
741 SELECT date '08-01-99';
747 SELECT date '08-01-1999';
753 SELECT date '01-08-99';
759 SELECT date '01-08-1999';
765 SELECT date '99-08-01';
766 ERROR: date/time field value out of range: "99-08-01"
767 LINE 1: SELECT date '99-08-01';
769 HINT: Perhaps you need a different "datestyle" setting.
770 SELECT date '1999-08-01';
776 SELECT date '99 01 08';
777 ERROR: date/time field value out of range: "99 01 08"
778 LINE 1: SELECT date '99 01 08';
780 HINT: Perhaps you need a different "datestyle" setting.
781 SELECT date '1999 01 08';
787 SELECT date '08 01 99';
793 SELECT date '08 01 1999';
799 SELECT date '01 08 99';
805 SELECT date '01 08 1999';
811 SELECT date '99 08 01';
812 ERROR: date/time field value out of range: "99 08 01"
813 LINE 1: SELECT date '99 08 01';
815 HINT: Perhaps you need a different "datestyle" setting.
816 SELECT date '1999 08 01';
822 -- Check upper and lower limits of date range
823 SELECT date '4714-11-24 BC';
829 SELECT date '4714-11-23 BC'; -- out of range
830 ERROR: date out of range: "4714-11-23 BC"
831 LINE 1: SELECT date '4714-11-23 BC';
833 SELECT date '5874897-12-31';
839 SELECT date '5874898-01-01'; -- out of range
840 ERROR: date out of range: "5874898-01-01"
841 LINE 1: SELECT date '5874898-01-01';
846 -- Leave most of it for the horology tests
848 SELECT f1 - date '2000-01-01' AS "Days From 2K" FROM DATE_TBL;
869 SELECT f1 - date 'epoch' AS "Days From Epoch" FROM DATE_TBL;
890 SELECT date 'yesterday' - date 'today' AS "One day";
896 SELECT date 'today' - date 'tomorrow' AS "One day";
902 SELECT date 'yesterday' - date 'tomorrow' AS "Two days";
908 SELECT date 'tomorrow' - date 'today' AS "One day";
914 SELECT date 'today' - date 'yesterday' AS "One day";
920 SELECT date 'tomorrow' - date 'yesterday' AS "Two days";
930 date_part('year', f1) AS year,
931 date_part('month', f1) AS month,
932 date_part('day', f1) AS day,
933 date_part('quarter', f1) AS quarter,
934 date_part('decade', f1) AS decade,
935 date_part('century', f1) AS century,
936 date_part('millennium', f1) AS millennium,
937 date_part('isoyear', f1) AS isoyear,
938 date_part('week', f1) AS week,
939 date_part('dow', f1) AS dow,
940 date_part('isodow', f1) AS isodow,
941 date_part('doy', f1) AS doy,
942 date_part('julian', f1) AS julian,
943 date_part('epoch', f1) AS epoch
945 date | year | month | day | quarter | decade | century | millennium | isoyear | week | dow | isodow | doy | julian | epoch
946 ---------------+-------+-------+-----+---------+--------+---------+------------+---------+------+-----+--------+-----+---------+---------------
947 04-09-1957 | 1957 | 4 | 9 | 2 | 195 | 20 | 2 | 1957 | 15 | 2 | 2 | 99 | 2435938 | -401760000
948 06-13-1957 | 1957 | 6 | 13 | 2 | 195 | 20 | 2 | 1957 | 24 | 4 | 4 | 164 | 2436003 | -396144000
949 02-28-1996 | 1996 | 2 | 28 | 1 | 199 | 20 | 2 | 1996 | 9 | 3 | 3 | 59 | 2450142 | 825465600
950 02-29-1996 | 1996 | 2 | 29 | 1 | 199 | 20 | 2 | 1996 | 9 | 4 | 4 | 60 | 2450143 | 825552000
951 03-01-1996 | 1996 | 3 | 1 | 1 | 199 | 20 | 2 | 1996 | 9 | 5 | 5 | 61 | 2450144 | 825638400
952 03-02-1996 | 1996 | 3 | 2 | 1 | 199 | 20 | 2 | 1996 | 9 | 6 | 6 | 62 | 2450145 | 825724800
953 02-28-1997 | 1997 | 2 | 28 | 1 | 199 | 20 | 2 | 1997 | 9 | 5 | 5 | 59 | 2450508 | 857088000
954 03-01-1997 | 1997 | 3 | 1 | 1 | 199 | 20 | 2 | 1997 | 9 | 6 | 6 | 60 | 2450509 | 857174400
955 03-02-1997 | 1997 | 3 | 2 | 1 | 199 | 20 | 2 | 1997 | 9 | 0 | 7 | 61 | 2450510 | 857260800
956 04-01-2000 | 2000 | 4 | 1 | 2 | 200 | 20 | 2 | 2000 | 13 | 6 | 6 | 92 | 2451636 | 954547200
957 04-02-2000 | 2000 | 4 | 2 | 2 | 200 | 20 | 2 | 2000 | 13 | 0 | 7 | 93 | 2451637 | 954633600
958 04-03-2000 | 2000 | 4 | 3 | 2 | 200 | 20 | 2 | 2000 | 14 | 1 | 1 | 94 | 2451638 | 954720000
959 04-08-2038 | 2038 | 4 | 8 | 2 | 203 | 21 | 3 | 2038 | 14 | 4 | 4 | 98 | 2465522 | 2154297600
960 04-09-2039 | 2039 | 4 | 9 | 2 | 203 | 21 | 3 | 2039 | 14 | 6 | 6 | 99 | 2465888 | 2185920000
961 04-10-2040 | 2040 | 4 | 10 | 2 | 204 | 21 | 3 | 2040 | 15 | 2 | 2 | 101 | 2466255 | 2217628800
962 04-10-2040 BC | -2040 | 4 | 10 | 2 | -204 | -21 | -3 | -2040 | 15 | 1 | 1 | 100 | 976430 | -126503251200
968 SELECT EXTRACT(EPOCH FROM DATE '1970-01-01'); -- 0
977 SELECT EXTRACT(CENTURY FROM DATE '0101-12-31 BC'); -- -2
983 SELECT EXTRACT(CENTURY FROM DATE '0100-12-31 BC'); -- -1
989 SELECT EXTRACT(CENTURY FROM DATE '0001-12-31 BC'); -- -1
995 SELECT EXTRACT(CENTURY FROM DATE '0001-01-01'); -- 1
1001 SELECT EXTRACT(CENTURY FROM DATE '0001-01-01 AD'); -- 1
1007 SELECT EXTRACT(CENTURY FROM DATE '1900-12-31'); -- 19
1013 SELECT EXTRACT(CENTURY FROM DATE '1901-01-01'); -- 20
1019 SELECT EXTRACT(CENTURY FROM DATE '2000-12-31'); -- 20
1025 SELECT EXTRACT(CENTURY FROM DATE '2001-01-01'); -- 21
1031 SELECT EXTRACT(CENTURY FROM CURRENT_DATE)>=21 AS True; -- true
1040 SELECT EXTRACT(MILLENNIUM FROM DATE '0001-12-31 BC'); -- -1
1046 SELECT EXTRACT(MILLENNIUM FROM DATE '0001-01-01 AD'); -- 1
1052 SELECT EXTRACT(MILLENNIUM FROM DATE '1000-12-31'); -- 1
1058 SELECT EXTRACT(MILLENNIUM FROM DATE '1001-01-01'); -- 2
1064 SELECT EXTRACT(MILLENNIUM FROM DATE '2000-12-31'); -- 2
1070 SELECT EXTRACT(MILLENNIUM FROM DATE '2001-01-01'); -- 3
1076 -- next test to be fixed on the turn of the next millennium;-)
1077 SELECT EXTRACT(MILLENNIUM FROM CURRENT_DATE); -- 3
1086 SELECT EXTRACT(DECADE FROM DATE '1994-12-25'); -- 199
1092 SELECT EXTRACT(DECADE FROM DATE '0010-01-01'); -- 1
1098 SELECT EXTRACT(DECADE FROM DATE '0009-12-31'); -- 0
1104 SELECT EXTRACT(DECADE FROM DATE '0001-01-01 BC'); -- 0
1110 SELECT EXTRACT(DECADE FROM DATE '0002-12-31 BC'); -- -1
1116 SELECT EXTRACT(DECADE FROM DATE '0011-01-01 BC'); -- -1
1122 SELECT EXTRACT(DECADE FROM DATE '0012-12-31 BC'); -- -2
1129 -- all possible fields
1131 SELECT EXTRACT(MICROSECONDS FROM DATE '2020-08-11');
1132 ERROR: date units "microseconds" not supported
1133 SELECT EXTRACT(MILLISECONDS FROM DATE '2020-08-11');
1134 ERROR: date units "milliseconds" not supported
1135 SELECT EXTRACT(SECOND FROM DATE '2020-08-11');
1136 ERROR: date units "second" not supported
1137 SELECT EXTRACT(MINUTE FROM DATE '2020-08-11');
1138 ERROR: date units "minute" not supported
1139 SELECT EXTRACT(HOUR FROM DATE '2020-08-11');
1140 ERROR: date units "hour" not supported
1141 SELECT EXTRACT(DAY FROM DATE '2020-08-11');
1147 SELECT EXTRACT(MONTH FROM DATE '2020-08-11');
1153 SELECT EXTRACT(YEAR FROM DATE '2020-08-11');
1159 SELECT EXTRACT(YEAR FROM DATE '2020-08-11 BC');
1165 SELECT EXTRACT(DECADE FROM DATE '2020-08-11');
1171 SELECT EXTRACT(CENTURY FROM DATE '2020-08-11');
1177 SELECT EXTRACT(MILLENNIUM FROM DATE '2020-08-11');
1183 SELECT EXTRACT(ISOYEAR FROM DATE '2020-08-11');
1189 SELECT EXTRACT(ISOYEAR FROM DATE '2020-08-11 BC');
1195 SELECT EXTRACT(QUARTER FROM DATE '2020-08-11');
1201 SELECT EXTRACT(WEEK FROM DATE '2020-08-11');
1207 SELECT EXTRACT(DOW FROM DATE '2020-08-11');
1213 SELECT EXTRACT(DOW FROM DATE '2020-08-16');
1219 SELECT EXTRACT(ISODOW FROM DATE '2020-08-11');
1225 SELECT EXTRACT(ISODOW FROM DATE '2020-08-16');
1231 SELECT EXTRACT(DOY FROM DATE '2020-08-11');
1237 SELECT EXTRACT(TIMEZONE FROM DATE '2020-08-11');
1238 ERROR: date units "timezone" not supported
1239 SELECT EXTRACT(TIMEZONE_M FROM DATE '2020-08-11');
1240 ERROR: date units "timezone_m" not supported
1241 SELECT EXTRACT(TIMEZONE_H FROM DATE '2020-08-11');
1242 ERROR: date units "timezone_h" not supported
1243 SELECT EXTRACT(EPOCH FROM DATE '2020-08-11');
1249 SELECT EXTRACT(JULIAN FROM DATE '2020-08-11');
1256 -- test trunc function!
1258 SELECT DATE_TRUNC('MILLENNIUM', TIMESTAMP '1970-03-20 04:30:00.00000'); -- 1001
1260 --------------------------
1261 Thu Jan 01 00:00:00 1001
1264 SELECT DATE_TRUNC('MILLENNIUM', DATE '1970-03-20'); -- 1001-01-01
1266 ------------------------------
1267 Thu Jan 01 00:00:00 1001 PST
1270 SELECT DATE_TRUNC('CENTURY', TIMESTAMP '1970-03-20 04:30:00.00000'); -- 1901
1272 --------------------------
1273 Tue Jan 01 00:00:00 1901
1276 SELECT DATE_TRUNC('CENTURY', DATE '1970-03-20'); -- 1901
1278 ------------------------------
1279 Tue Jan 01 00:00:00 1901 PST
1282 SELECT DATE_TRUNC('CENTURY', DATE '2004-08-10'); -- 2001-01-01
1284 ------------------------------
1285 Mon Jan 01 00:00:00 2001 PST
1288 SELECT DATE_TRUNC('CENTURY', DATE '0002-02-04'); -- 0001-01-01
1290 ------------------------------
1291 Mon Jan 01 00:00:00 0001 PST
1294 SELECT DATE_TRUNC('CENTURY', DATE '0055-08-10 BC'); -- 0100-01-01 BC
1296 ---------------------------------
1297 Tue Jan 01 00:00:00 0100 PST BC
1300 SELECT DATE_TRUNC('DECADE', DATE '1993-12-25'); -- 1990-01-01
1302 ------------------------------
1303 Mon Jan 01 00:00:00 1990 PST
1306 SELECT DATE_TRUNC('DECADE', DATE '0004-12-25'); -- 0001-01-01 BC
1308 ---------------------------------
1309 Sat Jan 01 00:00:00 0001 PST BC
1312 SELECT DATE_TRUNC('DECADE', DATE '0002-12-31 BC'); -- 0011-01-01 BC
1314 ---------------------------------
1315 Mon Jan 01 00:00:00 0011 PST BC
1321 select 'infinity'::date, '-infinity'::date;
1323 ----------+-----------
1324 infinity | -infinity
1327 select 'infinity'::date > 'today'::date as t;
1333 select '-infinity'::date < 'today'::date as t;
1339 select isfinite('infinity'::date), isfinite('-infinity'::date), isfinite('today'::date);
1340 isfinite | isfinite | isfinite
1341 ----------+----------+----------
1346 -- oscillating fields from non-finite date:
1348 SELECT EXTRACT(DAY FROM DATE 'infinity'); -- NULL
1354 SELECT EXTRACT(DAY FROM DATE '-infinity'); -- NULL
1360 -- all supported fields
1361 SELECT EXTRACT(DAY FROM DATE 'infinity'); -- NULL
1367 SELECT EXTRACT(MONTH FROM DATE 'infinity'); -- NULL
1373 SELECT EXTRACT(QUARTER FROM DATE 'infinity'); -- NULL
1379 SELECT EXTRACT(WEEK FROM DATE 'infinity'); -- NULL
1385 SELECT EXTRACT(DOW FROM DATE 'infinity'); -- NULL
1391 SELECT EXTRACT(ISODOW FROM DATE 'infinity'); -- NULL
1397 SELECT EXTRACT(DOY FROM DATE 'infinity'); -- NULL
1404 -- monotonic fields from non-finite date:
1406 SELECT EXTRACT(EPOCH FROM DATE 'infinity'); -- Infinity
1412 SELECT EXTRACT(EPOCH FROM DATE '-infinity'); -- -Infinity
1418 -- all supported fields
1419 SELECT EXTRACT(YEAR FROM DATE 'infinity'); -- Infinity
1425 SELECT EXTRACT(DECADE FROM DATE 'infinity'); -- Infinity
1431 SELECT EXTRACT(CENTURY FROM DATE 'infinity'); -- Infinity
1437 SELECT EXTRACT(MILLENNIUM FROM DATE 'infinity'); -- Infinity
1443 SELECT EXTRACT(JULIAN FROM DATE 'infinity'); -- Infinity
1449 SELECT EXTRACT(ISOYEAR FROM DATE 'infinity'); -- Infinity
1455 SELECT EXTRACT(EPOCH FROM DATE 'infinity'); -- Infinity
1462 -- wrong fields from non-finite date:
1464 SELECT EXTRACT(MICROSEC FROM DATE 'infinity'); -- error
1465 ERROR: date units "microsec" not recognized
1466 -- test constructors
1467 select make_date(2013, 7, 15);
1473 select make_date(-44, 3, 15);
1479 select make_time(8, 20, 0.0);
1486 select make_date(0, 7, 15);
1487 ERROR: date field value out of range: 0-07-15
1488 select make_date(2013, 2, 30);
1489 ERROR: date field value out of range: 2013-02-30
1490 select make_date(2013, 13, 1);
1491 ERROR: date field value out of range: 2013-13-01
1492 select make_date(2013, 11, -1);
1493 ERROR: date field value out of range: 2013-11--1
1494 select make_time(10, 55, 100.1);
1495 ERROR: time field value out of range: 10:55:100.1
1496 select make_time(24, 0, 2.1);
1497 ERROR: time field value out of range: 24:00:2.1