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';
843 -- Test non-error-throwing API
844 SELECT pg_input_is_valid('now', 'date');
850 SELECT pg_input_is_valid('garbage', 'date');
856 SELECT pg_input_is_valid('6874898-01-01', 'date');
862 SELECT * FROM pg_input_error_info('garbage', 'date');
863 message | detail | hint | sql_error_code
864 -----------------------------------------------+--------+------+----------------
865 invalid input syntax for type date: "garbage" | | | 22007
868 SELECT * FROM pg_input_error_info('6874898-01-01', 'date');
869 message | detail | hint | sql_error_code
870 ------------------------------------+--------+------+----------------
871 date out of range: "6874898-01-01" | | | 22008
877 -- Leave most of it for the horology tests
879 SELECT f1 - date '2000-01-01' AS "Days From 2K" FROM DATE_TBL;
900 SELECT f1 - date 'epoch' AS "Days From Epoch" FROM DATE_TBL;
921 SELECT date 'yesterday' - date 'today' AS "One day";
927 SELECT date 'today' - date 'tomorrow' AS "One day";
933 SELECT date 'yesterday' - date 'tomorrow' AS "Two days";
939 SELECT date 'tomorrow' - date 'today' AS "One day";
945 SELECT date 'today' - date 'yesterday' AS "One day";
951 SELECT date 'tomorrow' - date 'yesterday' AS "Two days";
961 date_part('year', f1) AS year,
962 date_part('month', f1) AS month,
963 date_part('day', f1) AS day,
964 date_part('quarter', f1) AS quarter,
965 date_part('decade', f1) AS decade,
966 date_part('century', f1) AS century,
967 date_part('millennium', f1) AS millennium,
968 date_part('isoyear', f1) AS isoyear,
969 date_part('week', f1) AS week,
970 date_part('dow', f1) AS dow,
971 date_part('isodow', f1) AS isodow,
972 date_part('doy', f1) AS doy,
973 date_part('julian', f1) AS julian,
974 date_part('epoch', f1) AS epoch
976 date | year | month | day | quarter | decade | century | millennium | isoyear | week | dow | isodow | doy | julian | epoch
977 ---------------+-------+-------+-----+---------+--------+---------+------------+---------+------+-----+--------+-----+---------+---------------
978 04-09-1957 | 1957 | 4 | 9 | 2 | 195 | 20 | 2 | 1957 | 15 | 2 | 2 | 99 | 2435938 | -401760000
979 06-13-1957 | 1957 | 6 | 13 | 2 | 195 | 20 | 2 | 1957 | 24 | 4 | 4 | 164 | 2436003 | -396144000
980 02-28-1996 | 1996 | 2 | 28 | 1 | 199 | 20 | 2 | 1996 | 9 | 3 | 3 | 59 | 2450142 | 825465600
981 02-29-1996 | 1996 | 2 | 29 | 1 | 199 | 20 | 2 | 1996 | 9 | 4 | 4 | 60 | 2450143 | 825552000
982 03-01-1996 | 1996 | 3 | 1 | 1 | 199 | 20 | 2 | 1996 | 9 | 5 | 5 | 61 | 2450144 | 825638400
983 03-02-1996 | 1996 | 3 | 2 | 1 | 199 | 20 | 2 | 1996 | 9 | 6 | 6 | 62 | 2450145 | 825724800
984 02-28-1997 | 1997 | 2 | 28 | 1 | 199 | 20 | 2 | 1997 | 9 | 5 | 5 | 59 | 2450508 | 857088000
985 03-01-1997 | 1997 | 3 | 1 | 1 | 199 | 20 | 2 | 1997 | 9 | 6 | 6 | 60 | 2450509 | 857174400
986 03-02-1997 | 1997 | 3 | 2 | 1 | 199 | 20 | 2 | 1997 | 9 | 0 | 7 | 61 | 2450510 | 857260800
987 04-01-2000 | 2000 | 4 | 1 | 2 | 200 | 20 | 2 | 2000 | 13 | 6 | 6 | 92 | 2451636 | 954547200
988 04-02-2000 | 2000 | 4 | 2 | 2 | 200 | 20 | 2 | 2000 | 13 | 0 | 7 | 93 | 2451637 | 954633600
989 04-03-2000 | 2000 | 4 | 3 | 2 | 200 | 20 | 2 | 2000 | 14 | 1 | 1 | 94 | 2451638 | 954720000
990 04-08-2038 | 2038 | 4 | 8 | 2 | 203 | 21 | 3 | 2038 | 14 | 4 | 4 | 98 | 2465522 | 2154297600
991 04-09-2039 | 2039 | 4 | 9 | 2 | 203 | 21 | 3 | 2039 | 14 | 6 | 6 | 99 | 2465888 | 2185920000
992 04-10-2040 | 2040 | 4 | 10 | 2 | 204 | 21 | 3 | 2040 | 15 | 2 | 2 | 101 | 2466255 | 2217628800
993 04-10-2040 BC | -2040 | 4 | 10 | 2 | -204 | -21 | -3 | -2040 | 15 | 1 | 1 | 100 | 976430 | -126503251200
999 SELECT EXTRACT(EPOCH FROM DATE '1970-01-01'); -- 0
1008 SELECT EXTRACT(CENTURY FROM DATE '0101-12-31 BC'); -- -2
1014 SELECT EXTRACT(CENTURY FROM DATE '0100-12-31 BC'); -- -1
1020 SELECT EXTRACT(CENTURY FROM DATE '0001-12-31 BC'); -- -1
1026 SELECT EXTRACT(CENTURY FROM DATE '0001-01-01'); -- 1
1032 SELECT EXTRACT(CENTURY FROM DATE '0001-01-01 AD'); -- 1
1038 SELECT EXTRACT(CENTURY FROM DATE '1900-12-31'); -- 19
1044 SELECT EXTRACT(CENTURY FROM DATE '1901-01-01'); -- 20
1050 SELECT EXTRACT(CENTURY FROM DATE '2000-12-31'); -- 20
1056 SELECT EXTRACT(CENTURY FROM DATE '2001-01-01'); -- 21
1062 SELECT EXTRACT(CENTURY FROM CURRENT_DATE)>=21 AS True; -- true
1071 SELECT EXTRACT(MILLENNIUM FROM DATE '0001-12-31 BC'); -- -1
1077 SELECT EXTRACT(MILLENNIUM FROM DATE '0001-01-01 AD'); -- 1
1083 SELECT EXTRACT(MILLENNIUM FROM DATE '1000-12-31'); -- 1
1089 SELECT EXTRACT(MILLENNIUM FROM DATE '1001-01-01'); -- 2
1095 SELECT EXTRACT(MILLENNIUM FROM DATE '2000-12-31'); -- 2
1101 SELECT EXTRACT(MILLENNIUM FROM DATE '2001-01-01'); -- 3
1107 -- next test to be fixed on the turn of the next millennium;-)
1108 SELECT EXTRACT(MILLENNIUM FROM CURRENT_DATE); -- 3
1117 SELECT EXTRACT(DECADE FROM DATE '1994-12-25'); -- 199
1123 SELECT EXTRACT(DECADE FROM DATE '0010-01-01'); -- 1
1129 SELECT EXTRACT(DECADE FROM DATE '0009-12-31'); -- 0
1135 SELECT EXTRACT(DECADE FROM DATE '0001-01-01 BC'); -- 0
1141 SELECT EXTRACT(DECADE FROM DATE '0002-12-31 BC'); -- -1
1147 SELECT EXTRACT(DECADE FROM DATE '0011-01-01 BC'); -- -1
1153 SELECT EXTRACT(DECADE FROM DATE '0012-12-31 BC'); -- -2
1160 -- all possible fields
1162 SELECT EXTRACT(MICROSECONDS FROM DATE '2020-08-11');
1163 ERROR: unit "microseconds" not supported for type date
1164 SELECT EXTRACT(MILLISECONDS FROM DATE '2020-08-11');
1165 ERROR: unit "milliseconds" not supported for type date
1166 SELECT EXTRACT(SECOND FROM DATE '2020-08-11');
1167 ERROR: unit "second" not supported for type date
1168 SELECT EXTRACT(MINUTE FROM DATE '2020-08-11');
1169 ERROR: unit "minute" not supported for type date
1170 SELECT EXTRACT(HOUR FROM DATE '2020-08-11');
1171 ERROR: unit "hour" not supported for type date
1172 SELECT EXTRACT(DAY FROM DATE '2020-08-11');
1178 SELECT EXTRACT(MONTH FROM DATE '2020-08-11');
1184 SELECT EXTRACT(YEAR FROM DATE '2020-08-11');
1190 SELECT EXTRACT(YEAR FROM DATE '2020-08-11 BC');
1196 SELECT EXTRACT(DECADE FROM DATE '2020-08-11');
1202 SELECT EXTRACT(CENTURY FROM DATE '2020-08-11');
1208 SELECT EXTRACT(MILLENNIUM FROM DATE '2020-08-11');
1214 SELECT EXTRACT(ISOYEAR FROM DATE '2020-08-11');
1220 SELECT EXTRACT(ISOYEAR FROM DATE '2020-08-11 BC');
1226 SELECT EXTRACT(QUARTER FROM DATE '2020-08-11');
1232 SELECT EXTRACT(WEEK FROM DATE '2020-08-11');
1238 SELECT EXTRACT(DOW FROM DATE '2020-08-11');
1244 SELECT EXTRACT(DOW FROM DATE '2020-08-16');
1250 SELECT EXTRACT(ISODOW FROM DATE '2020-08-11');
1256 SELECT EXTRACT(ISODOW FROM DATE '2020-08-16');
1262 SELECT EXTRACT(DOY FROM DATE '2020-08-11');
1268 SELECT EXTRACT(TIMEZONE FROM DATE '2020-08-11');
1269 ERROR: unit "timezone" not supported for type date
1270 SELECT EXTRACT(TIMEZONE_M FROM DATE '2020-08-11');
1271 ERROR: unit "timezone_m" not supported for type date
1272 SELECT EXTRACT(TIMEZONE_H FROM DATE '2020-08-11');
1273 ERROR: unit "timezone_h" not supported for type date
1274 SELECT EXTRACT(EPOCH FROM DATE '2020-08-11');
1280 SELECT EXTRACT(JULIAN FROM DATE '2020-08-11');
1287 -- test trunc function!
1289 SELECT DATE_TRUNC('MILLENNIUM', TIMESTAMP '1970-03-20 04:30:00.00000'); -- 1001
1291 --------------------------
1292 Thu Jan 01 00:00:00 1001
1295 SELECT DATE_TRUNC('MILLENNIUM', DATE '1970-03-20'); -- 1001-01-01
1297 ------------------------------
1298 Thu Jan 01 00:00:00 1001 LMT
1301 SELECT DATE_TRUNC('CENTURY', TIMESTAMP '1970-03-20 04:30:00.00000'); -- 1901
1303 --------------------------
1304 Tue Jan 01 00:00:00 1901
1307 SELECT DATE_TRUNC('CENTURY', DATE '1970-03-20'); -- 1901
1309 ------------------------------
1310 Tue Jan 01 00:00:00 1901 PST
1313 SELECT DATE_TRUNC('CENTURY', DATE '2004-08-10'); -- 2001-01-01
1315 ------------------------------
1316 Mon Jan 01 00:00:00 2001 PST
1319 SELECT DATE_TRUNC('CENTURY', DATE '0002-02-04'); -- 0001-01-01
1321 ------------------------------
1322 Mon Jan 01 00:00:00 0001 LMT
1325 SELECT DATE_TRUNC('CENTURY', DATE '0055-08-10 BC'); -- 0100-01-01 BC
1327 ---------------------------------
1328 Tue Jan 01 00:00:00 0100 LMT BC
1331 SELECT DATE_TRUNC('DECADE', DATE '1993-12-25'); -- 1990-01-01
1333 ------------------------------
1334 Mon Jan 01 00:00:00 1990 PST
1337 SELECT DATE_TRUNC('DECADE', DATE '0004-12-25'); -- 0001-01-01 BC
1339 ---------------------------------
1340 Sat Jan 01 00:00:00 0001 LMT BC
1343 SELECT DATE_TRUNC('DECADE', DATE '0002-12-31 BC'); -- 0011-01-01 BC
1345 ---------------------------------
1346 Mon Jan 01 00:00:00 0011 LMT BC
1352 select 'infinity'::date, '-infinity'::date;
1354 ----------+-----------
1355 infinity | -infinity
1358 select 'infinity'::date > 'today'::date as t;
1364 select '-infinity'::date < 'today'::date as t;
1370 select isfinite('infinity'::date), isfinite('-infinity'::date), isfinite('today'::date);
1371 isfinite | isfinite | isfinite
1372 ----------+----------+----------
1376 select 'infinity'::date = '+infinity'::date as t;
1383 -- oscillating fields from non-finite date:
1385 SELECT EXTRACT(DAY FROM DATE 'infinity'); -- NULL
1391 SELECT EXTRACT(DAY FROM DATE '-infinity'); -- NULL
1397 -- all supported fields
1398 SELECT EXTRACT(DAY FROM DATE 'infinity'); -- NULL
1404 SELECT EXTRACT(MONTH FROM DATE 'infinity'); -- NULL
1410 SELECT EXTRACT(QUARTER FROM DATE 'infinity'); -- NULL
1416 SELECT EXTRACT(WEEK FROM DATE 'infinity'); -- NULL
1422 SELECT EXTRACT(DOW FROM DATE 'infinity'); -- NULL
1428 SELECT EXTRACT(ISODOW FROM DATE 'infinity'); -- NULL
1434 SELECT EXTRACT(DOY FROM DATE 'infinity'); -- NULL
1441 -- monotonic fields from non-finite date:
1443 SELECT EXTRACT(EPOCH FROM DATE 'infinity'); -- Infinity
1449 SELECT EXTRACT(EPOCH FROM DATE '-infinity'); -- -Infinity
1455 -- all supported fields
1456 SELECT EXTRACT(YEAR FROM DATE 'infinity'); -- Infinity
1462 SELECT EXTRACT(DECADE FROM DATE 'infinity'); -- Infinity
1468 SELECT EXTRACT(CENTURY FROM DATE 'infinity'); -- Infinity
1474 SELECT EXTRACT(MILLENNIUM FROM DATE 'infinity'); -- Infinity
1480 SELECT EXTRACT(JULIAN FROM DATE 'infinity'); -- Infinity
1486 SELECT EXTRACT(ISOYEAR FROM DATE 'infinity'); -- Infinity
1492 SELECT EXTRACT(EPOCH FROM DATE 'infinity'); -- Infinity
1499 -- wrong fields from non-finite date:
1501 SELECT EXTRACT(MICROSEC FROM DATE 'infinity'); -- error
1502 ERROR: unit "microsec" not recognized for type date
1503 -- test constructors
1504 select make_date(2013, 7, 15);
1510 select make_date(-44, 3, 15);
1516 select make_time(8, 20, 0.0);
1523 select make_date(0, 7, 15);
1524 ERROR: date field value out of range: 0-07-15
1525 select make_date(2013, 2, 30);
1526 ERROR: date field value out of range: 2013-02-30
1527 select make_date(2013, 13, 1);
1528 ERROR: date field value out of range: 2013-13-01
1529 select make_date(2013, 11, -1);
1530 ERROR: date field value out of range: 2013-11--1
1531 SELECT make_date(-2147483648, 1, 1);
1532 ERROR: date field value out of range: -2147483648-01-01
1533 select make_time(10, 55, 100.1);
1534 ERROR: time field value out of range: 10:55:100.1
1535 select make_time(24, 0, 2.1);
1536 ERROR: time field value out of range: 24:00:2.1