5 SET IntervalStyle to postgres;
6 -- check acceptance of "time zone style"
7 SELECT INTERVAL '01:00' AS "One hour";
13 SELECT INTERVAL '+02:00' AS "Two hours";
19 SELECT INTERVAL '-08:00' AS "Eight hours";
25 SELECT INTERVAL '-1 +02:03' AS "22 hours ago...";
31 SELECT INTERVAL '-1 days +02:03' AS "22 hours ago...";
37 SELECT INTERVAL '1.5 weeks' AS "Ten days twelve hours";
39 -----------------------
43 SELECT INTERVAL '1.5 months' AS "One month 15 days";
49 SELECT INTERVAL '10 years -11 month -12 days +13:14' AS "9 years...";
51 ----------------------------------
52 9 years 1 mon -12 days +13:14:00
55 SELECT INTERVAL 'infinity' AS "eternity";
61 SELECT INTERVAL '-infinity' AS "beginning of time";
67 CREATE TABLE INTERVAL_TBL (f1 interval);
68 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 1 minute');
69 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 5 hour');
70 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 10 day');
71 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 34 year');
72 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 3 months');
73 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 14 seconds ago');
74 INSERT INTO INTERVAL_TBL (f1) VALUES ('1 day 2 hours 3 minutes 4 seconds');
75 INSERT INTO INTERVAL_TBL (f1) VALUES ('6 years');
76 INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months');
77 INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months 12 hours');
78 INSERT INTO INTERVAL_TBL (f1) VALUES ('infinity');
79 INSERT INTO INTERVAL_TBL (f1) VALUES ('-infinity');
80 -- badly formatted interval
81 INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted interval');
82 ERROR: invalid input syntax for type interval: "badly formatted interval"
83 LINE 1: INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted inter...
85 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
86 ERROR: invalid input syntax for type interval: "@ 30 eons ago"
87 LINE 1: INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
89 -- Test non-error-throwing API
90 SELECT pg_input_is_valid('1.5 weeks', 'interval');
96 SELECT pg_input_is_valid('garbage', 'interval');
102 SELECT pg_input_is_valid('@ 30 eons ago', 'interval');
108 SELECT * FROM pg_input_error_info('garbage', 'interval');
109 message | detail | hint | sql_error_code
110 ---------------------------------------------------+--------+------+----------------
111 invalid input syntax for type interval: "garbage" | | | 22007
114 SELECT * FROM pg_input_error_info('@ 30 eons ago', 'interval');
115 message | detail | hint | sql_error_code
116 ---------------------------------------------------------+--------+------+----------------
117 invalid input syntax for type interval: "@ 30 eons ago" | | | 22007
120 -- test interval operators
121 SELECT * FROM INTERVAL_TBL;
138 SELECT * FROM INTERVAL_TBL
139 WHERE INTERVAL_TBL.f1 <> interval '@ 10 days';
155 SELECT * FROM INTERVAL_TBL
156 WHERE INTERVAL_TBL.f1 <= interval '@ 5 hours';
165 SELECT * FROM INTERVAL_TBL
166 WHERE INTERVAL_TBL.f1 < interval '@ 1 day';
175 SELECT * FROM INTERVAL_TBL
176 WHERE INTERVAL_TBL.f1 = interval '@ 34 years';
182 SELECT * FROM INTERVAL_TBL
183 WHERE INTERVAL_TBL.f1 >= interval '@ 1 month';
194 SELECT * FROM INTERVAL_TBL
195 WHERE INTERVAL_TBL.f1 > interval '@ 3 seconds ago';
211 FROM INTERVAL_TBL r1, INTERVAL_TBL r2
213 ORDER BY r1.f1, r2.f1;
215 -----------------+-----------------
216 -00:00:14 | -infinity
222 1 day 02:03:04 | -infinity
223 1 day 02:03:04 | -00:00:14
224 1 day 02:03:04 | 00:01:00
225 1 day 02:03:04 | 05:00:00
230 10 days | 1 day 02:03:04
235 3 mons | 1 day 02:03:04
241 5 mons | 1 day 02:03:04
244 5 mons 12:00:00 | -infinity
245 5 mons 12:00:00 | -00:00:14
246 5 mons 12:00:00 | 00:01:00
247 5 mons 12:00:00 | 05:00:00
248 5 mons 12:00:00 | 1 day 02:03:04
249 5 mons 12:00:00 | 10 days
250 5 mons 12:00:00 | 3 mons
251 5 mons 12:00:00 | 5 mons
256 6 years | 1 day 02:03:04
260 6 years | 5 mons 12:00:00
265 34 years | 1 day 02:03:04
269 34 years | 5 mons 12:00:00
275 infinity | 1 day 02:03:04
279 infinity | 5 mons 12:00:00
285 SELECT f1, -f1 FROM INTERVAL_TBL;
287 -----------------+-------------------
294 1 day 02:03:04 | -1 days -02:03:04
297 5 mons 12:00:00 | -5 mons -12:00:00
302 SELECT -('-2147483648 months'::interval); -- should fail
303 ERROR: interval out of range
304 SELECT -('-2147483647 months'::interval); -- ok
306 ------------------------
307 178956970 years 7 mons
310 SELECT -('-2147483648 days'::interval); -- should fail
311 ERROR: interval out of range
312 SELECT -('-2147483647 days'::interval); -- ok
318 SELECT -('-9223372036854775808 us'::interval); -- should fail
319 ERROR: interval out of range
320 SELECT -('-9223372036854775807 us'::interval); -- ok
322 -------------------------
323 2562047788:00:54.775807
326 SELECT -('-2147483647 months -2147483647 days -9223372036854775807 us'::interval); -- should fail
327 ERROR: interval out of range
328 -- Test intervals that are large enough to overflow 64 bits in comparisons
329 CREATE TEMP TABLE INTERVAL_TBL_OF (f1 interval);
330 INSERT INTO INTERVAL_TBL_OF (f1) VALUES
331 ('2147483647 days 2147483647 months'),
332 ('2147483647 days -2147483648 months'),
334 ('-2147483648 days 2147483647 months'),
335 ('-2147483648 days -2147483648 months');
336 -- these should fail as out-of-range
337 INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483648 days');
338 ERROR: interval field value out of range: "2147483648 days"
339 LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483648 days');
341 INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483649 days');
342 ERROR: interval field value out of range: "-2147483649 days"
343 LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483649 days')...
345 INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483647 years');
346 ERROR: interval out of range
347 LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483647 years')...
349 INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483648 years');
350 ERROR: interval out of range
351 LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483648 years'...
353 -- Test edge-case overflow detection in interval multiplication
354 select extract(epoch from '256 microseconds'::interval * (2^55)::float8);
355 ERROR: interval out of range
357 FROM INTERVAL_TBL_OF r1, INTERVAL_TBL_OF r2
359 ORDER BY r1.f1, r2.f1;
361 -------------------------------------------+-------------------------------------------
362 -178956970 years -8 mons +2147483647 days | -178956970 years -8 mons -2147483648 days
363 1 year | -178956970 years -8 mons -2147483648 days
364 1 year | -178956970 years -8 mons +2147483647 days
365 178956970 years 7 mons -2147483648 days | -178956970 years -8 mons -2147483648 days
366 178956970 years 7 mons -2147483648 days | -178956970 years -8 mons +2147483647 days
367 178956970 years 7 mons -2147483648 days | 1 year
368 178956970 years 7 mons 2147483647 days | -178956970 years -8 mons -2147483648 days
369 178956970 years 7 mons 2147483647 days | -178956970 years -8 mons +2147483647 days
370 178956970 years 7 mons 2147483647 days | 1 year
371 178956970 years 7 mons 2147483647 days | 178956970 years 7 mons -2147483648 days
374 CREATE INDEX ON INTERVAL_TBL_OF USING btree (f1);
375 SET enable_seqscan TO false;
377 SELECT f1 FROM INTERVAL_TBL_OF r1 ORDER BY f1;
379 --------------------------------------------------------------------
380 Index Only Scan using interval_tbl_of_f1_idx on interval_tbl_of r1
383 SELECT f1 FROM INTERVAL_TBL_OF r1 ORDER BY f1;
385 -------------------------------------------
386 -178956970 years -8 mons -2147483648 days
387 -178956970 years -8 mons +2147483647 days
389 178956970 years 7 mons -2147483648 days
390 178956970 years 7 mons 2147483647 days
393 RESET enable_seqscan;
394 -- subtracting about-to-overflow values should result in 0
395 SELECT f1 - f1 FROM INTERVAL_TBL_OF;
405 DROP TABLE INTERVAL_TBL_OF;
406 -- Test multiplication and division with intervals.
407 -- Floating point arithmetic rounding errors can lead to unexpected results,
408 -- though the code attempts to do the right thing and round up to days and
409 -- minutes to avoid results such as '3 days 24:00 hours' or '14:20:60'.
410 -- Note that it is expected for some day components to be greater than 29 and
411 -- some time components be greater than 23:59:59 due to how intervals are
412 -- stored internally.
413 CREATE TABLE INTERVAL_MULDIV_TBL (span interval);
414 COPY INTERVAL_MULDIV_TBL FROM STDIN;
415 SELECT span * 0.3 AS product
416 FROM INTERVAL_MULDIV_TBL;
418 ------------------------------------
419 1 year 12 days 122:24:00
420 -1 years -12 days +93:36:00
422 2 mons 13 days 01:22:28.8
423 -10 mons +120 days 37:28:21.6567
426 24 years 11 mons 320 days 16:48:00
429 SELECT span * 8.2 AS product
430 FROM INTERVAL_MULDIV_TBL;
432 ---------------------------------------------
433 28 years 104 days 2961:36:00
434 -28 years -104 days +2942:24:00
436 6 years 1 mon -197 days +93:34:27.2
437 -24 years -7 mons +3946 days 640:15:11.9498
438 2 years 8 mons 24 days
439 9 years 6 mons 24 days
440 682 years 7 mons 8215 days 19:12:00
443 SELECT span / 10 AS quotient
444 FROM INTERVAL_MULDIV_TBL;
446 ----------------------------------
447 4 mons 4 days 40:48:00
448 -4 mons -4 days +31:12:00
451 -3 mons +30 days 12:29:27.2189
454 8 years 3 mons 126 days 21:36:00
457 SELECT span / 100 AS quotient
458 FROM INTERVAL_MULDIV_TBL;
460 -------------------------
465 -6 days +01:14:56.72189
468 9 mons 39 days 16:33:36
471 DROP TABLE INTERVAL_MULDIV_TBL;
472 SET DATESTYLE = 'postgres';
473 SET IntervalStyle to postgres_verbose;
474 SELECT * FROM INTERVAL_TBL;
476 -------------------------------
483 @ 1 day 2 hours 3 mins 4 secs
491 -- multiplication and division overflow test cases
492 SELECT '3000000 months'::interval * 1000;
493 ERROR: interval out of range
494 SELECT '3000000 months'::interval / 0.001;
495 ERROR: interval out of range
496 SELECT '3000000 days'::interval * 1000;
497 ERROR: interval out of range
498 SELECT '3000000 days'::interval / 0.001;
499 ERROR: interval out of range
500 SELECT '1 month 2146410 days'::interval * 1000.5002;
501 ERROR: interval out of range
502 SELECT '4611686018427387904 usec'::interval / 0.1;
503 ERROR: interval out of range
504 -- test avg(interval), which is somewhat fragile since people have been
505 -- known to change the allowed input syntax for type interval without
506 -- updating pg_aggregate.agginitval
507 select avg(f1) from interval_tbl where isfinite(f1);
509 -------------------------------------------------
510 @ 4 years 1 mon 10 days 4 hours 18 mins 23 secs
513 -- test long interval input
514 select '4 millenniums 5 centuries 4 decades 1 year 4 months 4 days 17 minutes 31 seconds'::interval;
516 --------------------------------------------
517 @ 4541 years 4 mons 4 days 17 mins 31 secs
520 -- test long interval output
521 -- Note: the actual maximum length of the interval output is longer,
522 -- but we need the test to work for both integer and floating-point
524 select '100000000y 10mon -1000000000d -100000h -10min -10.000001s ago'::interval;
526 ---------------------------------------------------------------------------------------
527 @ 100000000 years 10 mons -1000000000 days -100000 hours -10 mins -10.000001 secs ago
530 -- test justify_hours() and justify_days()
531 SELECT justify_hours(interval '6 months 3 days 52 hours 3 minutes 2 seconds') as "6 mons 5 days 4 hours 3 mins 2 seconds";
532 6 mons 5 days 4 hours 3 mins 2 seconds
533 ----------------------------------------
534 @ 6 mons 5 days 4 hours 3 mins 2 secs
537 SELECT justify_days(interval '6 months 36 days 5 hours 4 minutes 3 seconds') as "7 mons 6 days 5 hours 4 mins 3 seconds";
538 7 mons 6 days 5 hours 4 mins 3 seconds
539 ----------------------------------------
540 @ 7 mons 6 days 5 hours 4 mins 3 secs
543 SELECT justify_hours(interval '2147483647 days 24 hrs');
544 ERROR: interval out of range
545 SELECT justify_days(interval '2147483647 months 30 days');
546 ERROR: interval out of range
547 -- test justify_interval()
548 SELECT justify_interval(interval '1 month -1 hour') as "1 month -1 hour";
554 SELECT justify_interval(interval '2147483647 days 24 hrs');
556 -------------------------------
557 @ 5965232 years 4 mons 8 days
560 SELECT justify_interval(interval '-2147483648 days -24 hrs');
562 -----------------------------------
563 @ 5965232 years 4 mons 9 days ago
566 SELECT justify_interval(interval '2147483647 months 30 days');
567 ERROR: interval out of range
568 SELECT justify_interval(interval '-2147483648 months -30 days');
569 ERROR: interval out of range
570 SELECT justify_interval(interval '2147483647 months 30 days -24 hrs');
572 ----------------------------------
573 @ 178956970 years 7 mons 29 days
576 SELECT justify_interval(interval '-2147483648 months -30 days 24 hrs');
578 --------------------------------------
579 @ 178956970 years 8 mons 29 days ago
582 SELECT justify_interval(interval '2147483647 months -30 days 1440 hrs');
583 ERROR: interval out of range
584 SELECT justify_interval(interval '-2147483648 months 30 days -1440 hrs');
585 ERROR: interval out of range
586 -- test fractional second input, and detection of duplicate units
587 SET DATESTYLE = 'ISO';
588 SET IntervalStyle TO postgres;
589 SELECT '1 millisecond'::interval, '1 microsecond'::interval,
590 '500 seconds 99 milliseconds 51 microseconds'::interval;
591 interval | interval | interval
592 --------------+-----------------+-----------------
593 00:00:00.001 | 00:00:00.000001 | 00:08:20.099051
596 SELECT '3 days 5 milliseconds'::interval;
598 ---------------------
602 SELECT '1 second 2 seconds'::interval; -- error
603 ERROR: invalid input syntax for type interval: "1 second 2 seconds"
604 LINE 1: SELECT '1 second 2 seconds'::interval;
606 SELECT '10 milliseconds 20 milliseconds'::interval; -- error
607 ERROR: invalid input syntax for type interval: "10 milliseconds 20 milliseconds"
608 LINE 1: SELECT '10 milliseconds 20 milliseconds'::interval;
610 SELECT '5.5 seconds 3 milliseconds'::interval; -- error
611 ERROR: invalid input syntax for type interval: "5.5 seconds 3 milliseconds"
612 LINE 1: SELECT '5.5 seconds 3 milliseconds'::interval;
614 SELECT '1:20:05 5 microseconds'::interval; -- error
615 ERROR: invalid input syntax for type interval: "1:20:05 5 microseconds"
616 LINE 1: SELECT '1:20:05 5 microseconds'::interval;
618 SELECT '1 day 1 day'::interval; -- error
619 ERROR: invalid input syntax for type interval: "1 day 1 day"
620 LINE 1: SELECT '1 day 1 day'::interval;
622 SELECT interval '1-2'; -- SQL year-month literal
628 SELECT interval '999' second; -- oversize leading field is ok
634 SELECT interval '999' minute;
640 SELECT interval '999' hour;
646 SELECT interval '999' day;
652 SELECT interval '999' month;
658 -- test SQL-spec syntaxes for restricted field sets
659 SELECT interval '1' year;
665 SELECT interval '2' month;
671 SELECT interval '3' day;
677 SELECT interval '4' hour;
683 SELECT interval '5' minute;
689 SELECT interval '6' second;
695 SELECT interval '1' year to month;
701 SELECT interval '1-2' year to month;
707 SELECT interval '1 2' day to hour;
713 SELECT interval '1 2:03' day to hour;
719 SELECT interval '1 2:03:04' day to hour;
725 SELECT interval '1 2' day to minute;
726 ERROR: invalid input syntax for type interval: "1 2"
727 LINE 1: SELECT interval '1 2' day to minute;
729 SELECT interval '1 2:03' day to minute;
735 SELECT interval '1 2:03:04' day to minute;
741 SELECT interval '1 2' day to second;
742 ERROR: invalid input syntax for type interval: "1 2"
743 LINE 1: SELECT interval '1 2' day to second;
745 SELECT interval '1 2:03' day to second;
751 SELECT interval '1 2:03:04' day to second;
757 SELECT interval '1 2' hour to minute;
758 ERROR: invalid input syntax for type interval: "1 2"
759 LINE 1: SELECT interval '1 2' hour to minute;
761 SELECT interval '1 2:03' hour to minute;
767 SELECT interval '1 2:03:04' hour to minute;
773 SELECT interval '1 2' hour to second;
774 ERROR: invalid input syntax for type interval: "1 2"
775 LINE 1: SELECT interval '1 2' hour to second;
777 SELECT interval '1 2:03' hour to second;
783 SELECT interval '1 2:03:04' hour to second;
789 SELECT interval '1 2' minute to second;
790 ERROR: invalid input syntax for type interval: "1 2"
791 LINE 1: SELECT interval '1 2' minute to second;
793 SELECT interval '1 2:03' minute to second;
799 SELECT interval '1 2:03:04' minute to second;
805 SELECT interval '1 +2:03' minute to second;
811 SELECT interval '1 +2:03:04' minute to second;
817 SELECT interval '1 -2:03' minute to second;
823 SELECT interval '1 -2:03:04' minute to second;
829 SELECT interval '123 11' day to hour; -- ok
835 SELECT interval '123 11' day; -- not ok
836 ERROR: invalid input syntax for type interval: "123 11"
837 LINE 1: SELECT interval '123 11' day;
839 SELECT interval '123 11'; -- not ok, too ambiguous
840 ERROR: invalid input syntax for type interval: "123 11"
841 LINE 1: SELECT interval '123 11';
843 SELECT interval '123 2:03 -2:04'; -- not ok, redundant hh:mm fields
844 ERROR: invalid input syntax for type interval: "123 2:03 -2:04"
845 LINE 1: SELECT interval '123 2:03 -2:04';
847 -- test syntaxes for restricted precision
848 SELECT interval(0) '1 day 01:23:45.6789';
854 SELECT interval(2) '1 day 01:23:45.6789';
860 SELECT interval '12:34.5678' minute to second(2); -- per SQL spec
866 SELECT interval '1.234' second;
872 SELECT interval '1.234' second(2);
878 SELECT interval '1 2.345' day to second(2);
879 ERROR: invalid input syntax for type interval: "1 2.345"
880 LINE 1: SELECT interval '1 2.345' day to second(2);
882 SELECT interval '1 2:03' day to second(2);
888 SELECT interval '1 2:03.4567' day to second(2);
894 SELECT interval '1 2:03:04.5678' day to second(2);
900 SELECT interval '1 2.345' hour to second(2);
901 ERROR: invalid input syntax for type interval: "1 2.345"
902 LINE 1: SELECT interval '1 2.345' hour to second(2);
904 SELECT interval '1 2:03.45678' hour to second(2);
910 SELECT interval '1 2:03:04.5678' hour to second(2);
916 SELECT interval '1 2.3456' minute to second(2);
917 ERROR: invalid input syntax for type interval: "1 2.3456"
918 LINE 1: SELECT interval '1 2.3456' minute to second(2);
920 SELECT interval '1 2:03.5678' minute to second(2);
926 SELECT interval '1 2:03:04.5678' minute to second(2);
932 SELECT interval '2562047788:00:54.775807' second(2); -- out of range
933 ERROR: interval out of range
934 LINE 1: SELECT interval '2562047788:00:54.775807' second(2);
936 SELECT interval '-2562047788:00:54.775807' second(2); -- out of range
937 ERROR: interval out of range
938 LINE 1: SELECT interval '-2562047788:00:54.775807' second(2);
940 -- test casting to restricted precision (bug #14479)
941 SELECT f1, f1::INTERVAL DAY TO MINUTE AS "minutes",
942 (f1 + INTERVAL '1 month')::INTERVAL MONTH::INTERVAL YEAR AS "years"
945 -----------------+-----------------+-----------
946 00:01:00 | 00:01:00 | 00:00:00
947 05:00:00 | 05:00:00 | 00:00:00
948 10 days | 10 days | 00:00:00
949 34 years | 34 years | 34 years
950 3 mons | 3 mons | 00:00:00
951 -00:00:14 | 00:00:00 | 00:00:00
952 1 day 02:03:04 | 1 day 02:03:00 | 00:00:00
953 6 years | 6 years | 6 years
954 5 mons | 5 mons | 00:00:00
955 5 mons 12:00:00 | 5 mons 12:00:00 | 00:00:00
956 infinity | infinity | infinity
957 -infinity | -infinity | -infinity
960 -- test inputting and outputting SQL standard interval literals
961 SET IntervalStyle TO sql_standard;
962 SELECT interval '0' AS "zero",
963 interval '1-2' year to month AS "year-month",
964 interval '1 2:03:04' day to second AS "day-time",
965 - interval '1-2' AS "negative year-month",
966 - interval '1 2:03:04' AS "negative day-time";
967 zero | year-month | day-time | negative year-month | negative day-time
968 ------+------------+-----------+---------------------+-------------------
969 0 | 1-2 | 1 2:03:04 | -1-2 | -1 2:03:04
972 -- test input of some not-quite-standard interval values in the sql style
973 SET IntervalStyle TO postgres;
974 SELECT interval '+1 -1:00:00',
975 interval '-1 +1:00:00',
976 interval '+1-2 -3 +4:05:06.789',
977 interval '-1-2 +3 -4:05:06.789';
978 interval | interval | interval | interval
979 -----------------+-------------------+-------------------------------------+----------------------------------------
980 1 day -01:00:00 | -1 days +01:00:00 | 1 year 2 mons -3 days +04:05:06.789 | -1 years -2 mons +3 days -04:05:06.789
983 -- cases that trigger sign-matching rules in the sql style
984 SELECT interval '-23 hours 45 min 12.34 sec',
985 interval '-1 day 23 hours 45 min 12.34 sec',
986 interval '-1 year 2 months 1 day 23 hours 45 min 12.34 sec',
987 interval '-1 year 2 months 1 day 23 hours 45 min +12.34 sec';
988 interval | interval | interval | interval
989 --------------+----------------------+-----------------------------+-----------------------------
990 -22:14:47.66 | -1 days +23:45:12.34 | -10 mons +1 day 23:45:12.34 | -10 mons +1 day 23:45:12.34
993 -- test output of couple non-standard interval values in the sql style
994 SET IntervalStyle TO sql_standard;
995 SELECT interval '1 day -1 hours',
996 interval '-1 days +1 hours',
997 interval '1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds',
998 - interval '1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds';
999 interval | interval | interval | ?column?
1000 ------------------+------------------+----------------------+----------------------
1001 +0-0 +1 -1:00:00 | +0-0 -1 +1:00:00 | +1-2 -3 +4:05:06.789 | -1-2 +3 -4:05:06.789
1004 -- cases that trigger sign-matching rules in the sql style
1005 SELECT interval '-23 hours 45 min 12.34 sec',
1006 interval '-1 day 23 hours 45 min 12.34 sec',
1007 interval '-1 year 2 months 1 day 23 hours 45 min 12.34 sec',
1008 interval '-1 year 2 months 1 day 23 hours 45 min +12.34 sec';
1009 interval | interval | interval | interval
1010 --------------+----------------+----------------------+-----------------------
1011 -23:45:12.34 | -1 23:45:12.34 | -1-2 -1 -23:45:12.34 | -0-10 +1 +23:45:12.34
1014 -- edge case for sign-matching rules
1015 SELECT interval ''; -- error
1016 ERROR: invalid input syntax for type interval: ""
1017 LINE 1: SELECT interval '';
1019 -- test outputting iso8601 intervals
1020 SET IntervalStyle to iso_8601;
1021 select interval '0' AS "zero",
1022 interval '1-2' AS "a year 2 months",
1023 interval '1 2:03:04' AS "a bit over a day",
1024 interval '2:03:04.45679' AS "a bit over 2 hours",
1025 (interval '1-2' + interval '3 4:05:06.7') AS "all fields",
1026 (interval '1-2' - interval '3 4:05:06.7') AS "mixed sign",
1027 (- interval '1-2' + interval '3 4:05:06.7') AS "negative";
1028 zero | a year 2 months | a bit over a day | a bit over 2 hours | all fields | mixed sign | negative
1029 ------+-----------------+------------------+--------------------+------------------+----------------------+--------------------
1030 PT0S | P1Y2M | P1DT2H3M4S | PT2H3M4.45679S | P1Y2M3DT4H5M6.7S | P1Y2M-3DT-4H-5M-6.7S | P-1Y-2M3DT4H5M6.7S
1033 -- test inputting ISO 8601 4.4.2.1 "Format With Time Unit Designators"
1034 SET IntervalStyle to sql_standard;
1035 select interval 'P0Y' AS "zero",
1036 interval 'P1Y2M' AS "a year 2 months",
1037 interval 'P1W' AS "a week",
1038 interval 'P1DT2H3M4S' AS "a bit over a day",
1039 interval 'P1Y2M3DT4H5M6.7S' AS "all fields",
1040 interval 'P-1Y-2M-3DT-4H-5M-6.7S' AS "negative",
1041 interval 'PT-0.1S' AS "fractional second";
1042 zero | a year 2 months | a week | a bit over a day | all fields | negative | fractional second
1043 ------+-----------------+-----------+------------------+--------------------+--------------------+-------------------
1044 0 | 1-2 | 7 0:00:00 | 1 2:03:04 | +1-2 +3 +4:05:06.7 | -1-2 -3 -4:05:06.7 | -0:00:00.1
1047 -- test inputting ISO 8601 4.4.2.2 "Alternative Format"
1048 SET IntervalStyle to postgres;
1049 select interval 'P00021015T103020' AS "ISO8601 Basic Format",
1050 interval 'P0002-10-15T10:30:20' AS "ISO8601 Extended Format";
1051 ISO8601 Basic Format | ISO8601 Extended Format
1052 ----------------------------------+----------------------------------
1053 2 years 10 mons 15 days 10:30:20 | 2 years 10 mons 15 days 10:30:20
1056 -- Make sure optional ISO8601 alternative format fields are optional.
1057 select interval 'P0002' AS "year only",
1058 interval 'P0002-10' AS "year month",
1059 interval 'P0002-10-15' AS "year month day",
1060 interval 'P0002T1S' AS "year only plus time",
1061 interval 'P0002-10T1S' AS "year month plus time",
1062 interval 'P0002-10-15T1S' AS "year month day plus time",
1063 interval 'PT10' AS "hour only",
1064 interval 'PT10:30' AS "hour minute";
1065 year only | year month | year month day | year only plus time | year month plus time | year month day plus time | hour only | hour minute
1066 -----------+-----------------+-------------------------+---------------------+--------------------------+----------------------------------+-----------+-------------
1067 2 years | 2 years 10 mons | 2 years 10 mons 15 days | 2 years 00:00:01 | 2 years 10 mons 00:00:01 | 2 years 10 mons 15 days 00:00:01 | 10:00:00 | 10:30:00
1070 -- Check handling of fractional fields in ISO8601 format.
1071 select interval 'P1Y0M3DT4H5M6S';
1073 ------------------------
1074 1 year 3 days 04:05:06
1077 select interval 'P1.0Y0M3DT4H5M6S';
1079 ------------------------
1080 1 year 3 days 04:05:06
1083 select interval 'P1.1Y0M3DT4H5M6S';
1085 ------------------------------
1086 1 year 1 mon 3 days 04:05:06
1089 select interval 'P1.Y0M3DT4H5M6S';
1091 ------------------------
1092 1 year 3 days 04:05:06
1095 select interval 'P.1Y0M3DT4H5M6S';
1097 -----------------------
1098 1 mon 3 days 04:05:06
1101 select interval 'P10.5e4Y'; -- not per spec, but we've historically taken it
1107 select interval 'P.Y0M3DT4H5M6S'; -- error
1108 ERROR: invalid input syntax for type interval: "P.Y0M3DT4H5M6S"
1109 LINE 1: select interval 'P.Y0M3DT4H5M6S';
1111 -- test a couple rounding cases that changed since 8.3 w/ HAVE_INT64_TIMESTAMP.
1112 SET IntervalStyle to postgres_verbose;
1113 select interval '-10 mons -3 days +03:55:06.70';
1115 --------------------------------------------------
1116 @ 10 mons 3 days -3 hours -55 mins -6.7 secs ago
1119 select interval '1 year 2 mons 3 days 04:05:06.699999';
1121 -----------------------------------------------------
1122 @ 1 year 2 mons 3 days 4 hours 5 mins 6.699999 secs
1125 select interval '0:0:0.7', interval '@ 0.70 secs', interval '0.7 seconds';
1126 interval | interval | interval
1127 ------------+------------+------------
1128 @ 0.7 secs | @ 0.7 secs | @ 0.7 secs
1131 -- test time fields using entire 64 bit microseconds range
1132 select interval '2562047788.01521550194 hours';
1134 -----------------------------------
1135 @ 2562047788 hours 54.775807 secs
1138 select interval '-2562047788.01521550222 hours';
1140 ---------------------------------------
1141 @ 2562047788 hours 54.775808 secs ago
1144 select interval '153722867280.912930117 minutes';
1146 -----------------------------------
1147 @ 2562047788 hours 54.775807 secs
1150 select interval '-153722867280.912930133 minutes';
1152 ---------------------------------------
1153 @ 2562047788 hours 54.775808 secs ago
1156 select interval '9223372036854.775807 seconds';
1158 -----------------------------------
1159 @ 2562047788 hours 54.775807 secs
1162 select interval '-9223372036854.775808 seconds';
1164 ---------------------------------------
1165 @ 2562047788 hours 54.775808 secs ago
1168 select interval '9223372036854775.807 milliseconds';
1170 -----------------------------------
1171 @ 2562047788 hours 54.775807 secs
1174 select interval '-9223372036854775.808 milliseconds';
1176 ---------------------------------------
1177 @ 2562047788 hours 54.775808 secs ago
1180 select interval '9223372036854775807 microseconds';
1182 -----------------------------------
1183 @ 2562047788 hours 54.775807 secs
1186 select interval '-9223372036854775808 microseconds';
1188 ---------------------------------------
1189 @ 2562047788 hours 54.775808 secs ago
1192 select interval 'PT2562047788H54.775807S';
1194 -----------------------------------
1195 @ 2562047788 hours 54.775807 secs
1198 select interval 'PT-2562047788H-54.775808S';
1200 ---------------------------------------
1201 @ 2562047788 hours 54.775808 secs ago
1204 select interval 'PT2562047788:00:54.775807';
1206 -----------------------------------
1207 @ 2562047788 hours 54.775807 secs
1210 select interval 'PT2562047788.0152155019444';
1212 -----------------------------------
1213 @ 2562047788 hours 54.775429 secs
1216 select interval 'PT-2562047788.0152155022222';
1218 ---------------------------------------
1219 @ 2562047788 hours 54.775429 secs ago
1222 -- overflow each date/time field
1223 select interval '2147483648 years';
1224 ERROR: interval field value out of range: "2147483648 years"
1225 LINE 1: select interval '2147483648 years';
1227 select interval '-2147483649 years';
1228 ERROR: interval field value out of range: "-2147483649 years"
1229 LINE 1: select interval '-2147483649 years';
1231 select interval '2147483648 months';
1232 ERROR: interval field value out of range: "2147483648 months"
1233 LINE 1: select interval '2147483648 months';
1235 select interval '-2147483649 months';
1236 ERROR: interval field value out of range: "-2147483649 months"
1237 LINE 1: select interval '-2147483649 months';
1239 select interval '2147483648 days';
1240 ERROR: interval field value out of range: "2147483648 days"
1241 LINE 1: select interval '2147483648 days';
1243 select interval '-2147483649 days';
1244 ERROR: interval field value out of range: "-2147483649 days"
1245 LINE 1: select interval '-2147483649 days';
1247 select interval '2562047789 hours';
1248 ERROR: interval field value out of range: "2562047789 hours"
1249 LINE 1: select interval '2562047789 hours';
1251 select interval '-2562047789 hours';
1252 ERROR: interval field value out of range: "-2562047789 hours"
1253 LINE 1: select interval '-2562047789 hours';
1255 select interval '153722867281 minutes';
1256 ERROR: interval field value out of range: "153722867281 minutes"
1257 LINE 1: select interval '153722867281 minutes';
1259 select interval '-153722867281 minutes';
1260 ERROR: interval field value out of range: "-153722867281 minutes"
1261 LINE 1: select interval '-153722867281 minutes';
1263 select interval '9223372036855 seconds';
1264 ERROR: interval field value out of range: "9223372036855 seconds"
1265 LINE 1: select interval '9223372036855 seconds';
1267 select interval '-9223372036855 seconds';
1268 ERROR: interval field value out of range: "-9223372036855 seconds"
1269 LINE 1: select interval '-9223372036855 seconds';
1271 select interval '9223372036854777 millisecond';
1272 ERROR: interval field value out of range: "9223372036854777 millisecond"
1273 LINE 1: select interval '9223372036854777 millisecond';
1275 select interval '-9223372036854777 millisecond';
1276 ERROR: interval field value out of range: "-9223372036854777 millisecond"
1277 LINE 1: select interval '-9223372036854777 millisecond';
1279 select interval '9223372036854775808 microsecond';
1280 ERROR: interval field value out of range: "9223372036854775808 microsecond"
1281 LINE 1: select interval '9223372036854775808 microsecond';
1283 select interval '-9223372036854775809 microsecond';
1284 ERROR: interval field value out of range: "-9223372036854775809 microsecond"
1285 LINE 1: select interval '-9223372036854775809 microsecond';
1287 select interval 'P2147483648';
1288 ERROR: interval field value out of range: "P2147483648"
1289 LINE 1: select interval 'P2147483648';
1291 select interval 'P-2147483649';
1292 ERROR: interval field value out of range: "P-2147483649"
1293 LINE 1: select interval 'P-2147483649';
1295 select interval 'P1-2147483647-2147483647';
1296 ERROR: interval out of range
1297 LINE 1: select interval 'P1-2147483647-2147483647';
1299 select interval 'PT2562047789';
1300 ERROR: interval field value out of range: "PT2562047789"
1301 LINE 1: select interval 'PT2562047789';
1303 select interval 'PT-2562047789';
1304 ERROR: interval field value out of range: "PT-2562047789"
1305 LINE 1: select interval 'PT-2562047789';
1307 -- overflow with date/time unit aliases
1308 select interval '2147483647 weeks';
1309 ERROR: interval field value out of range: "2147483647 weeks"
1310 LINE 1: select interval '2147483647 weeks';
1312 select interval '-2147483648 weeks';
1313 ERROR: interval field value out of range: "-2147483648 weeks"
1314 LINE 1: select interval '-2147483648 weeks';
1316 select interval '2147483647 decades';
1317 ERROR: interval field value out of range: "2147483647 decades"
1318 LINE 1: select interval '2147483647 decades';
1320 select interval '-2147483648 decades';
1321 ERROR: interval field value out of range: "-2147483648 decades"
1322 LINE 1: select interval '-2147483648 decades';
1324 select interval '2147483647 centuries';
1325 ERROR: interval field value out of range: "2147483647 centuries"
1326 LINE 1: select interval '2147483647 centuries';
1328 select interval '-2147483648 centuries';
1329 ERROR: interval field value out of range: "-2147483648 centuries"
1330 LINE 1: select interval '-2147483648 centuries';
1332 select interval '2147483647 millennium';
1333 ERROR: interval field value out of range: "2147483647 millennium"
1334 LINE 1: select interval '2147483647 millennium';
1336 select interval '-2147483648 millennium';
1337 ERROR: interval field value out of range: "-2147483648 millennium"
1338 LINE 1: select interval '-2147483648 millennium';
1340 select interval '1 week 2147483647 days';
1341 ERROR: interval field value out of range: "1 week 2147483647 days"
1342 LINE 1: select interval '1 week 2147483647 days';
1344 select interval '-1 week -2147483648 days';
1345 ERROR: interval field value out of range: "-1 week -2147483648 days"
1346 LINE 1: select interval '-1 week -2147483648 days';
1348 select interval '2147483647 days 1 week';
1349 ERROR: interval field value out of range: "2147483647 days 1 week"
1350 LINE 1: select interval '2147483647 days 1 week';
1352 select interval '-2147483648 days -1 week';
1353 ERROR: interval field value out of range: "-2147483648 days -1 week"
1354 LINE 1: select interval '-2147483648 days -1 week';
1356 select interval 'P1W2147483647D';
1357 ERROR: interval field value out of range: "P1W2147483647D"
1358 LINE 1: select interval 'P1W2147483647D';
1360 select interval 'P-1W-2147483648D';
1361 ERROR: interval field value out of range: "P-1W-2147483648D"
1362 LINE 1: select interval 'P-1W-2147483648D';
1364 select interval 'P2147483647D1W';
1365 ERROR: interval field value out of range: "P2147483647D1W"
1366 LINE 1: select interval 'P2147483647D1W';
1368 select interval 'P-2147483648D-1W';
1369 ERROR: interval field value out of range: "P-2147483648D-1W"
1370 LINE 1: select interval 'P-2147483648D-1W';
1372 select interval '1 decade 2147483647 years';
1373 ERROR: interval field value out of range: "1 decade 2147483647 years"
1374 LINE 1: select interval '1 decade 2147483647 years';
1376 select interval '1 century 2147483647 years';
1377 ERROR: interval field value out of range: "1 century 2147483647 years"
1378 LINE 1: select interval '1 century 2147483647 years';
1380 select interval '1 millennium 2147483647 years';
1381 ERROR: interval field value out of range: "1 millennium 2147483647 years"
1382 LINE 1: select interval '1 millennium 2147483647 years';
1384 select interval '-1 decade -2147483648 years';
1385 ERROR: interval field value out of range: "-1 decade -2147483648 years"
1386 LINE 1: select interval '-1 decade -2147483648 years';
1388 select interval '-1 century -2147483648 years';
1389 ERROR: interval field value out of range: "-1 century -2147483648 years"
1390 LINE 1: select interval '-1 century -2147483648 years';
1392 select interval '-1 millennium -2147483648 years';
1393 ERROR: interval field value out of range: "-1 millennium -2147483648 years"
1394 LINE 1: select interval '-1 millennium -2147483648 years';
1396 select interval '2147483647 years 1 decade';
1397 ERROR: interval field value out of range: "2147483647 years 1 decade"
1398 LINE 1: select interval '2147483647 years 1 decade';
1400 select interval '2147483647 years 1 century';
1401 ERROR: interval field value out of range: "2147483647 years 1 century"
1402 LINE 1: select interval '2147483647 years 1 century';
1404 select interval '2147483647 years 1 millennium';
1405 ERROR: interval field value out of range: "2147483647 years 1 millennium"
1406 LINE 1: select interval '2147483647 years 1 millennium';
1408 select interval '-2147483648 years -1 decade';
1409 ERROR: interval field value out of range: "-2147483648 years -1 decade"
1410 LINE 1: select interval '-2147483648 years -1 decade';
1412 select interval '-2147483648 years -1 century';
1413 ERROR: interval field value out of range: "-2147483648 years -1 century"
1414 LINE 1: select interval '-2147483648 years -1 century';
1416 select interval '-2147483648 years -1 millennium';
1417 ERROR: interval field value out of range: "-2147483648 years -1 millennium"
1418 LINE 1: select interval '-2147483648 years -1 millennium';
1420 -- overflowing with fractional fields - postgres format
1421 select interval '0.1 millennium 2147483647 months';
1422 ERROR: interval field value out of range: "0.1 millennium 2147483647 months"
1423 LINE 1: select interval '0.1 millennium 2147483647 months';
1425 select interval '0.1 centuries 2147483647 months';
1426 ERROR: interval field value out of range: "0.1 centuries 2147483647 months"
1427 LINE 1: select interval '0.1 centuries 2147483647 months';
1429 select interval '0.1 decades 2147483647 months';
1430 ERROR: interval field value out of range: "0.1 decades 2147483647 months"
1431 LINE 1: select interval '0.1 decades 2147483647 months';
1433 select interval '0.1 yrs 2147483647 months';
1434 ERROR: interval field value out of range: "0.1 yrs 2147483647 months"
1435 LINE 1: select interval '0.1 yrs 2147483647 months';
1437 select interval '-0.1 millennium -2147483648 months';
1438 ERROR: interval field value out of range: "-0.1 millennium -2147483648 months"
1439 LINE 1: select interval '-0.1 millennium -2147483648 months';
1441 select interval '-0.1 centuries -2147483648 months';
1442 ERROR: interval field value out of range: "-0.1 centuries -2147483648 months"
1443 LINE 1: select interval '-0.1 centuries -2147483648 months';
1445 select interval '-0.1 decades -2147483648 months';
1446 ERROR: interval field value out of range: "-0.1 decades -2147483648 months"
1447 LINE 1: select interval '-0.1 decades -2147483648 months';
1449 select interval '-0.1 yrs -2147483648 months';
1450 ERROR: interval field value out of range: "-0.1 yrs -2147483648 months"
1451 LINE 1: select interval '-0.1 yrs -2147483648 months';
1453 select interval '2147483647 months 0.1 millennium';
1454 ERROR: interval field value out of range: "2147483647 months 0.1 millennium"
1455 LINE 1: select interval '2147483647 months 0.1 millennium';
1457 select interval '2147483647 months 0.1 centuries';
1458 ERROR: interval field value out of range: "2147483647 months 0.1 centuries"
1459 LINE 1: select interval '2147483647 months 0.1 centuries';
1461 select interval '2147483647 months 0.1 decades';
1462 ERROR: interval field value out of range: "2147483647 months 0.1 decades"
1463 LINE 1: select interval '2147483647 months 0.1 decades';
1465 select interval '2147483647 months 0.1 yrs';
1466 ERROR: interval field value out of range: "2147483647 months 0.1 yrs"
1467 LINE 1: select interval '2147483647 months 0.1 yrs';
1469 select interval '-2147483648 months -0.1 millennium';
1470 ERROR: interval field value out of range: "-2147483648 months -0.1 millennium"
1471 LINE 1: select interval '-2147483648 months -0.1 millennium';
1473 select interval '-2147483648 months -0.1 centuries';
1474 ERROR: interval field value out of range: "-2147483648 months -0.1 centuries"
1475 LINE 1: select interval '-2147483648 months -0.1 centuries';
1477 select interval '-2147483648 months -0.1 decades';
1478 ERROR: interval field value out of range: "-2147483648 months -0.1 decades"
1479 LINE 1: select interval '-2147483648 months -0.1 decades';
1481 select interval '-2147483648 months -0.1 yrs';
1482 ERROR: interval field value out of range: "-2147483648 months -0.1 yrs"
1483 LINE 1: select interval '-2147483648 months -0.1 yrs';
1485 select interval '0.1 months 2147483647 days';
1486 ERROR: interval field value out of range: "0.1 months 2147483647 days"
1487 LINE 1: select interval '0.1 months 2147483647 days';
1489 select interval '-0.1 months -2147483648 days';
1490 ERROR: interval field value out of range: "-0.1 months -2147483648 days"
1491 LINE 1: select interval '-0.1 months -2147483648 days';
1493 select interval '2147483647 days 0.1 months';
1494 ERROR: interval field value out of range: "2147483647 days 0.1 months"
1495 LINE 1: select interval '2147483647 days 0.1 months';
1497 select interval '-2147483648 days -0.1 months';
1498 ERROR: interval field value out of range: "-2147483648 days -0.1 months"
1499 LINE 1: select interval '-2147483648 days -0.1 months';
1501 select interval '0.5 weeks 2147483647 days';
1502 ERROR: interval field value out of range: "0.5 weeks 2147483647 days"
1503 LINE 1: select interval '0.5 weeks 2147483647 days';
1505 select interval '-0.5 weeks -2147483648 days';
1506 ERROR: interval field value out of range: "-0.5 weeks -2147483648 days"
1507 LINE 1: select interval '-0.5 weeks -2147483648 days';
1509 select interval '2147483647 days 0.5 weeks';
1510 ERROR: interval field value out of range: "2147483647 days 0.5 weeks"
1511 LINE 1: select interval '2147483647 days 0.5 weeks';
1513 select interval '-2147483648 days -0.5 weeks';
1514 ERROR: interval field value out of range: "-2147483648 days -0.5 weeks"
1515 LINE 1: select interval '-2147483648 days -0.5 weeks';
1517 select interval '0.01 months 9223372036854775807 microseconds';
1518 ERROR: interval field value out of range: "0.01 months 9223372036854775807 microseconds"
1519 LINE 1: select interval '0.01 months 9223372036854775807 microsecond...
1521 select interval '-0.01 months -9223372036854775808 microseconds';
1522 ERROR: interval field value out of range: "-0.01 months -9223372036854775808 microseconds"
1523 LINE 1: select interval '-0.01 months -9223372036854775808 microseco...
1525 select interval '9223372036854775807 microseconds 0.01 months';
1526 ERROR: interval field value out of range: "9223372036854775807 microseconds 0.01 months"
1527 LINE 1: select interval '9223372036854775807 microseconds 0.01 month...
1529 select interval '-9223372036854775808 microseconds -0.01 months';
1530 ERROR: interval field value out of range: "-9223372036854775808 microseconds -0.01 months"
1531 LINE 1: select interval '-9223372036854775808 microseconds -0.01 mon...
1533 select interval '0.1 weeks 9223372036854775807 microseconds';
1534 ERROR: interval field value out of range: "0.1 weeks 9223372036854775807 microseconds"
1535 LINE 1: select interval '0.1 weeks 9223372036854775807 microseconds'...
1537 select interval '-0.1 weeks -9223372036854775808 microseconds';
1538 ERROR: interval field value out of range: "-0.1 weeks -9223372036854775808 microseconds"
1539 LINE 1: select interval '-0.1 weeks -9223372036854775808 microsecond...
1541 select interval '9223372036854775807 microseconds 0.1 weeks';
1542 ERROR: interval field value out of range: "9223372036854775807 microseconds 0.1 weeks"
1543 LINE 1: select interval '9223372036854775807 microseconds 0.1 weeks'...
1545 select interval '-9223372036854775808 microseconds -0.1 weeks';
1546 ERROR: interval field value out of range: "-9223372036854775808 microseconds -0.1 weeks"
1547 LINE 1: select interval '-9223372036854775808 microseconds -0.1 week...
1549 select interval '0.1 days 9223372036854775807 microseconds';
1550 ERROR: interval field value out of range: "0.1 days 9223372036854775807 microseconds"
1551 LINE 1: select interval '0.1 days 9223372036854775807 microseconds';
1553 select interval '-0.1 days -9223372036854775808 microseconds';
1554 ERROR: interval field value out of range: "-0.1 days -9223372036854775808 microseconds"
1555 LINE 1: select interval '-0.1 days -9223372036854775808 microseconds...
1557 select interval '9223372036854775807 microseconds 0.1 days';
1558 ERROR: interval field value out of range: "9223372036854775807 microseconds 0.1 days"
1559 LINE 1: select interval '9223372036854775807 microseconds 0.1 days';
1561 select interval '-9223372036854775808 microseconds -0.1 days';
1562 ERROR: interval field value out of range: "-9223372036854775808 microseconds -0.1 days"
1563 LINE 1: select interval '-9223372036854775808 microseconds -0.1 days...
1565 -- overflowing with fractional fields - ISO8601 format
1566 select interval 'P0.1Y2147483647M';
1567 ERROR: interval field value out of range: "P0.1Y2147483647M"
1568 LINE 1: select interval 'P0.1Y2147483647M';
1570 select interval 'P-0.1Y-2147483648M';
1571 ERROR: interval field value out of range: "P-0.1Y-2147483648M"
1572 LINE 1: select interval 'P-0.1Y-2147483648M';
1574 select interval 'P2147483647M0.1Y';
1575 ERROR: interval field value out of range: "P2147483647M0.1Y"
1576 LINE 1: select interval 'P2147483647M0.1Y';
1578 select interval 'P-2147483648M-0.1Y';
1579 ERROR: interval field value out of range: "P-2147483648M-0.1Y"
1580 LINE 1: select interval 'P-2147483648M-0.1Y';
1582 select interval 'P0.1M2147483647D';
1583 ERROR: interval field value out of range: "P0.1M2147483647D"
1584 LINE 1: select interval 'P0.1M2147483647D';
1586 select interval 'P-0.1M-2147483648D';
1587 ERROR: interval field value out of range: "P-0.1M-2147483648D"
1588 LINE 1: select interval 'P-0.1M-2147483648D';
1590 select interval 'P2147483647D0.1M';
1591 ERROR: interval field value out of range: "P2147483647D0.1M"
1592 LINE 1: select interval 'P2147483647D0.1M';
1594 select interval 'P-2147483648D-0.1M';
1595 ERROR: interval field value out of range: "P-2147483648D-0.1M"
1596 LINE 1: select interval 'P-2147483648D-0.1M';
1598 select interval 'P0.5W2147483647D';
1599 ERROR: interval field value out of range: "P0.5W2147483647D"
1600 LINE 1: select interval 'P0.5W2147483647D';
1602 select interval 'P-0.5W-2147483648D';
1603 ERROR: interval field value out of range: "P-0.5W-2147483648D"
1604 LINE 1: select interval 'P-0.5W-2147483648D';
1606 select interval 'P2147483647D0.5W';
1607 ERROR: interval field value out of range: "P2147483647D0.5W"
1608 LINE 1: select interval 'P2147483647D0.5W';
1610 select interval 'P-2147483648D-0.5W';
1611 ERROR: interval field value out of range: "P-2147483648D-0.5W"
1612 LINE 1: select interval 'P-2147483648D-0.5W';
1614 select interval 'P0.01MT2562047788H54.775807S';
1615 ERROR: interval field value out of range: "P0.01MT2562047788H54.775807S"
1616 LINE 1: select interval 'P0.01MT2562047788H54.775807S';
1618 select interval 'P-0.01MT-2562047788H-54.775808S';
1619 ERROR: interval field value out of range: "P-0.01MT-2562047788H-54.775808S"
1620 LINE 1: select interval 'P-0.01MT-2562047788H-54.775808S';
1622 select interval 'P0.1DT2562047788H54.775807S';
1623 ERROR: interval field value out of range: "P0.1DT2562047788H54.775807S"
1624 LINE 1: select interval 'P0.1DT2562047788H54.775807S';
1626 select interval 'P-0.1DT-2562047788H-54.775808S';
1627 ERROR: interval field value out of range: "P-0.1DT-2562047788H-54.775808S"
1628 LINE 1: select interval 'P-0.1DT-2562047788H-54.775808S';
1630 select interval 'PT2562047788.1H54.775807S';
1631 ERROR: interval field value out of range: "PT2562047788.1H54.775807S"
1632 LINE 1: select interval 'PT2562047788.1H54.775807S';
1634 select interval 'PT-2562047788.1H-54.775808S';
1635 ERROR: interval field value out of range: "PT-2562047788.1H-54.775808S"
1636 LINE 1: select interval 'PT-2562047788.1H-54.775808S';
1638 select interval 'PT2562047788H0.1M54.775807S';
1639 ERROR: interval field value out of range: "PT2562047788H0.1M54.775807S"
1640 LINE 1: select interval 'PT2562047788H0.1M54.775807S';
1642 select interval 'PT-2562047788H-0.1M-54.775808S';
1643 ERROR: interval field value out of range: "PT-2562047788H-0.1M-54.775808S"
1644 LINE 1: select interval 'PT-2562047788H-0.1M-54.775808S';
1646 -- overflowing with fractional fields - ISO8601 alternative format
1647 select interval 'P0.1-2147483647-00';
1648 ERROR: interval field value out of range: "P0.1-2147483647-00"
1649 LINE 1: select interval 'P0.1-2147483647-00';
1651 select interval 'P00-0.1-2147483647';
1652 ERROR: interval field value out of range: "P00-0.1-2147483647"
1653 LINE 1: select interval 'P00-0.1-2147483647';
1655 select interval 'P00-0.01-00T2562047788:00:54.775807';
1656 ERROR: interval field value out of range: "P00-0.01-00T2562047788:00:54.775807"
1657 LINE 1: select interval 'P00-0.01-00T2562047788:00:54.775807';
1659 select interval 'P00-00-0.1T2562047788:00:54.775807';
1660 ERROR: interval field value out of range: "P00-00-0.1T2562047788:00:54.775807"
1661 LINE 1: select interval 'P00-00-0.1T2562047788:00:54.775807';
1663 select interval 'PT2562047788.1:00:54.775807';
1664 ERROR: interval field value out of range: "PT2562047788.1:00:54.775807"
1665 LINE 1: select interval 'PT2562047788.1:00:54.775807';
1667 select interval 'PT2562047788:01.:54.775807';
1668 ERROR: interval field value out of range: "PT2562047788:01.:54.775807"
1669 LINE 1: select interval 'PT2562047788:01.:54.775807';
1671 -- overflowing with fractional fields - SQL standard format
1672 select interval '0.1 2562047788:0:54.775807';
1673 ERROR: interval field value out of range: "0.1 2562047788:0:54.775807"
1674 LINE 1: select interval '0.1 2562047788:0:54.775807';
1676 select interval '0.1 2562047788:0:54.775808 ago';
1677 ERROR: interval field value out of range: "0.1 2562047788:0:54.775808 ago"
1678 LINE 1: select interval '0.1 2562047788:0:54.775808 ago';
1680 select interval '2562047788.1:0:54.775807';
1681 ERROR: interval field value out of range: "2562047788.1:0:54.775807"
1682 LINE 1: select interval '2562047788.1:0:54.775807';
1684 select interval '2562047788.1:0:54.775808 ago';
1685 ERROR: interval field value out of range: "2562047788.1:0:54.775808 ago"
1686 LINE 1: select interval '2562047788.1:0:54.775808 ago';
1688 select interval '2562047788:0.1:54.775807';
1689 ERROR: invalid input syntax for type interval: "2562047788:0.1:54.775807"
1690 LINE 1: select interval '2562047788:0.1:54.775807';
1692 select interval '2562047788:0.1:54.775808 ago';
1693 ERROR: invalid input syntax for type interval: "2562047788:0.1:54.775808 ago"
1694 LINE 1: select interval '2562047788:0.1:54.775808 ago';
1696 -- overflowing using AGO with INT_MIN
1697 select interval '-2147483648 months ago';
1698 ERROR: interval field value out of range: "-2147483648 months ago"
1699 LINE 1: select interval '-2147483648 months ago';
1701 select interval '-2147483648 days ago';
1702 ERROR: interval field value out of range: "-2147483648 days ago"
1703 LINE 1: select interval '-2147483648 days ago';
1705 select interval '-9223372036854775808 microseconds ago';
1706 ERROR: interval field value out of range: "-9223372036854775808 microseconds ago"
1707 LINE 1: select interval '-9223372036854775808 microseconds ago';
1709 select interval '-2147483648 months -2147483648 days -9223372036854775808 microseconds ago';
1710 ERROR: interval field value out of range: "-2147483648 months -2147483648 days -9223372036854775808 microseconds ago"
1711 LINE 1: select interval '-2147483648 months -2147483648 days -922337...
1713 -- overflowing using make_interval
1714 select make_interval(years := 178956971);
1715 ERROR: interval out of range
1716 select make_interval(years := -178956971);
1717 ERROR: interval out of range
1718 select make_interval(years := 1, months := 2147483647);
1719 ERROR: interval out of range
1720 select make_interval(years := -1, months := -2147483648);
1721 ERROR: interval out of range
1722 select make_interval(weeks := 306783379);
1723 ERROR: interval out of range
1724 select make_interval(weeks := -306783379);
1725 ERROR: interval out of range
1726 select make_interval(weeks := 1, days := 2147483647);
1727 ERROR: interval out of range
1728 select make_interval(weeks := -1, days := -2147483648);
1729 ERROR: interval out of range
1730 select make_interval(secs := 1e308);
1731 ERROR: value out of range: overflow
1732 select make_interval(secs := 1e18);
1733 ERROR: interval out of range
1734 select make_interval(secs := -1e18);
1735 ERROR: interval out of range
1736 select make_interval(mins := 1, secs := 9223372036800.0);
1737 ERROR: interval out of range
1738 select make_interval(mins := -1, secs := -9223372036800.0);
1739 ERROR: interval out of range
1740 -- test that INT_MIN number is formatted properly
1741 SET IntervalStyle to postgres;
1742 select interval '-2147483647 months -2147483648 days -9223372036854775808 us';
1744 --------------------------------------------------------------------
1745 -178956970 years -7 mons -2147483648 days -2562047788:00:54.775808
1748 SET IntervalStyle to sql_standard;
1749 select interval '-2147483647 months -2147483648 days -9223372036854775808 us';
1751 ---------------------------------------------------
1752 -178956970-7 -2147483648 -2562047788:00:54.775808
1755 SET IntervalStyle to iso_8601;
1756 select interval '-2147483647 months -2147483648 days -9223372036854775808 us';
1758 -----------------------------------------------------
1759 P-178956970Y-7M-2147483648DT-2562047788H-54.775808S
1762 SET IntervalStyle to postgres_verbose;
1763 select interval '-2147483647 months -2147483648 days -9223372036854775808 us';
1765 ------------------------------------------------------------------------------
1766 @ 178956970 years 7 mons 2147483648 days 2562047788 hours 54.775808 secs ago
1769 -- check that '30 days' equals '1 month' according to the hash function
1770 select '30 days'::interval = '1 month'::interval as t;
1776 select interval_hash('30 days'::interval) = interval_hash('1 month'::interval) as t;
1782 -- numeric constructor
1783 select make_interval(years := 2);
1789 select make_interval(years := 1, months := 6);
1795 select make_interval(years := 1, months := -1, weeks := 5, days := -7, hours := 25, mins := -180);
1797 ----------------------------
1798 @ 11 mons 28 days 22 hours
1801 select make_interval() = make_interval(years := 0, months := 0, weeks := 0, days := 0, mins := 0, secs := 0.0);
1807 select make_interval(hours := -2, mins := -10, secs := -25.3);
1809 ---------------------------------
1810 @ 2 hours 10 mins 25.3 secs ago
1813 select make_interval(years := 'inf'::float::int);
1814 ERROR: integer out of range
1815 select make_interval(months := 'NaN'::float::int);
1816 ERROR: integer out of range
1817 select make_interval(secs := 'inf');
1818 ERROR: interval out of range
1819 select make_interval(secs := 'NaN');
1820 ERROR: interval out of range
1821 select make_interval(secs := 7e12);
1823 ------------------------------------
1824 @ 1944444444 hours 26 mins 40 secs
1831 EXTRACT(MICROSECOND FROM f1) AS MICROSECOND,
1832 EXTRACT(MILLISECOND FROM f1) AS MILLISECOND,
1833 EXTRACT(SECOND FROM f1) AS SECOND,
1834 EXTRACT(MINUTE FROM f1) AS MINUTE,
1835 EXTRACT(HOUR FROM f1) AS HOUR,
1836 EXTRACT(DAY FROM f1) AS DAY,
1837 EXTRACT(WEEK FROM f1) AS WEEK,
1838 EXTRACT(MONTH FROM f1) AS MONTH,
1839 EXTRACT(QUARTER FROM f1) AS QUARTER,
1840 EXTRACT(YEAR FROM f1) AS YEAR,
1841 EXTRACT(DECADE FROM f1) AS DECADE,
1842 EXTRACT(CENTURY FROM f1) AS CENTURY,
1843 EXTRACT(MILLENNIUM FROM f1) AS MILLENNIUM,
1844 EXTRACT(EPOCH FROM f1) AS EPOCH
1846 f1 | microsecond | millisecond | second | minute | hour | day | week | month | quarter | year | decade | century | millennium | epoch
1847 -------------------------------+-------------+-------------+------------+--------+-----------+-----------+------+-------+---------+-----------+-----------+-----------+------------+-------------------
1848 @ 1 min | 0 | 0.000 | 0.000000 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 60.000000
1849 @ 5 hours | 0 | 0.000 | 0.000000 | 0 | 5 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 18000.000000
1850 @ 10 days | 0 | 0.000 | 0.000000 | 0 | 0 | 10 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 864000.000000
1851 @ 34 years | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 0 | 1 | 34 | 3 | 0 | 0 | 1072958400.000000
1852 @ 3 mons | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 3 | 2 | 0 | 0 | 0 | 0 | 7776000.000000
1853 @ 14 secs ago | -14000000 | -14000.000 | -14.000000 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | -14.000000
1854 @ 1 day 2 hours 3 mins 4 secs | 4000000 | 4000.000 | 4.000000 | 3 | 2 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 93784.000000
1855 @ 6 years | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 0 | 1 | 6 | 0 | 0 | 0 | 189345600.000000
1856 @ 5 mons | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 5 | 2 | 0 | 0 | 0 | 0 | 12960000.000000
1857 @ 5 mons 12 hours | 0 | 0.000 | 0.000000 | 0 | 12 | 0 | 0 | 5 | 2 | 0 | 0 | 0 | 0 | 13003200.000000
1858 infinity | | | | | Infinity | Infinity | | | | Infinity | Infinity | Infinity | Infinity | Infinity
1859 -infinity | | | | | -Infinity | -Infinity | | | | -Infinity | -Infinity | -Infinity | -Infinity | -Infinity
1863 EXTRACT(MICROSECOND FROM -f1) AS MICROSECOND,
1864 EXTRACT(MILLISECOND FROM -f1) AS MILLISECOND,
1865 EXTRACT(SECOND FROM -f1) AS SECOND,
1866 EXTRACT(MINUTE FROM -f1) AS MINUTE,
1867 EXTRACT(HOUR FROM -f1) AS HOUR,
1868 EXTRACT(DAY FROM -f1) AS DAY,
1869 EXTRACT(WEEK FROM -f1) AS WEEK,
1870 EXTRACT(MONTH FROM -f1) AS MONTH,
1871 EXTRACT(QUARTER FROM -f1) AS QUARTER,
1872 EXTRACT(YEAR FROM -f1) AS YEAR,
1873 EXTRACT(DECADE FROM -f1) AS DECADE,
1874 EXTRACT(CENTURY FROM -f1) AS CENTURY,
1875 EXTRACT(MILLENNIUM FROM -f1) AS MILLENNIUM,
1876 EXTRACT(EPOCH FROM -f1) AS EPOCH
1878 ?column? | microsecond | millisecond | second | minute | hour | day | week | month | quarter | year | decade | century | millennium | epoch
1879 -----------------------------------+-------------+-------------+-----------+--------+-----------+-----------+------+-------+---------+-----------+-----------+-----------+------------+--------------------
1880 @ 1 min ago | 0 | 0.000 | 0.000000 | -1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | -60.000000
1881 @ 5 hours ago | 0 | 0.000 | 0.000000 | 0 | -5 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | -18000.000000
1882 @ 10 days ago | 0 | 0.000 | 0.000000 | 0 | 0 | -10 | -1 | 0 | 1 | 0 | 0 | 0 | 0 | -864000.000000
1883 @ 34 years ago | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 0 | -1 | -34 | -3 | 0 | 0 | -1072958400.000000
1884 @ 3 mons ago | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | -3 | -2 | 0 | 0 | 0 | 0 | -7776000.000000
1885 @ 14 secs | 14000000 | 14000.000 | 14.000000 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 14.000000
1886 @ 1 day 2 hours 3 mins 4 secs ago | -4000000 | -4000.000 | -4.000000 | -3 | -2 | -1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | -93784.000000
1887 @ 6 years ago | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 0 | -1 | -6 | 0 | 0 | 0 | -189345600.000000
1888 @ 5 mons ago | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | -5 | -2 | 0 | 0 | 0 | 0 | -12960000.000000
1889 @ 5 mons 12 hours ago | 0 | 0.000 | 0.000000 | 0 | -12 | 0 | 0 | -5 | -2 | 0 | 0 | 0 | 0 | -13003200.000000
1890 -infinity | | | | | -Infinity | -Infinity | | | | -Infinity | -Infinity | -Infinity | -Infinity | -Infinity
1891 infinity | | | | | Infinity | Infinity | | | | Infinity | Infinity | Infinity | Infinity | Infinity
1894 SELECT EXTRACT(FORTNIGHT FROM INTERVAL '2 days'); -- error
1895 ERROR: unit "fortnight" not recognized for type interval
1896 SELECT EXTRACT(TIMEZONE FROM INTERVAL '2 days'); -- error
1897 ERROR: unit "timezone" not supported for type interval
1898 SELECT EXTRACT(DECADE FROM INTERVAL '100 y');
1904 SELECT EXTRACT(DECADE FROM INTERVAL '99 y');
1910 SELECT EXTRACT(DECADE FROM INTERVAL '-99 y');
1916 SELECT EXTRACT(DECADE FROM INTERVAL '-100 y');
1922 SELECT EXTRACT(CENTURY FROM INTERVAL '100 y');
1928 SELECT EXTRACT(CENTURY FROM INTERVAL '99 y');
1934 SELECT EXTRACT(CENTURY FROM INTERVAL '-99 y');
1940 SELECT EXTRACT(CENTURY FROM INTERVAL '-100 y');
1946 -- date_part implementation is mostly the same as extract, so only
1947 -- test a few cases for additional coverage.
1949 date_part('microsecond', f1) AS microsecond,
1950 date_part('millisecond', f1) AS millisecond,
1951 date_part('second', f1) AS second,
1952 date_part('epoch', f1) AS epoch
1954 f1 | microsecond | millisecond | second | epoch
1955 -------------------------------+-------------+-------------+--------+------------
1956 @ 1 min | 0 | 0 | 0 | 60
1957 @ 5 hours | 0 | 0 | 0 | 18000
1958 @ 10 days | 0 | 0 | 0 | 864000
1959 @ 34 years | 0 | 0 | 0 | 1072958400
1960 @ 3 mons | 0 | 0 | 0 | 7776000
1961 @ 14 secs ago | -14000000 | -14000 | -14 | -14
1962 @ 1 day 2 hours 3 mins 4 secs | 4000000 | 4000 | 4 | 93784
1963 @ 6 years | 0 | 0 | 0 | 189345600
1964 @ 5 mons | 0 | 0 | 0 | 12960000
1965 @ 5 mons 12 hours | 0 | 0 | 0 | 13003200
1966 infinity | | | | Infinity
1967 -infinity | | | | -Infinity
1970 -- internal overflow test case
1971 SELECT extract(epoch from interval '1000000000 days');
1973 -----------------------
1974 86400000000000.000000
1978 -- test infinite intervals
1980 -- largest finite intervals
1981 SELECT interval '-2147483648 months -2147483648 days -9223372036854775807 us';
1983 ------------------------------------------------------------------------------
1984 @ 178956970 years 8 mons 2147483648 days 2562047788 hours 54.775807 secs ago
1987 SELECT interval '2147483647 months 2147483647 days 9223372036854775806 us';
1989 --------------------------------------------------------------------------
1990 @ 178956970 years 7 mons 2147483647 days 2562047788 hours 54.775806 secs
1993 -- infinite intervals
1994 SELECT interval '-2147483648 months -2147483648 days -9223372036854775808 us';
2000 SELECT interval '2147483647 months 2147483647 days 9223372036854775807 us';
2006 CREATE TABLE INFINITE_INTERVAL_TBL (i interval);
2007 INSERT INTO INFINITE_INTERVAL_TBL VALUES ('infinity'), ('-infinity'), ('1 year 2 days 3 hours');
2008 SELECT i, isfinite(i) FROM INFINITE_INTERVAL_TBL;
2010 -------------------------+----------
2013 @ 1 year 2 days 3 hours | t
2016 -- test basic arithmetic
2017 CREATE FUNCTION eval(expr text)
2023 EXECUTE 'select '||expr INTO result;
2025 EXCEPTION WHEN OTHERS THEN
2030 SELECT d AS date, i AS interval,
2031 eval(format('date %L + interval %L', d, i)) AS plus,
2032 eval(format('date %L - interval %L', d, i)) AS minus
2033 FROM (VALUES (date '-infinity'),
2034 (date '1995-08-06'),
2035 (date 'infinity')) AS t1(d),
2036 (VALUES (interval '-infinity'),
2037 (interval 'infinity')) AS t2(i);
2038 date | interval | plus | minus
2039 ------------+-----------+------------------------+------------------------
2040 -infinity | -infinity | -infinity | timestamp out of range
2041 -infinity | infinity | timestamp out of range | -infinity
2042 1995-08-06 | -infinity | -infinity | infinity
2043 1995-08-06 | infinity | infinity | -infinity
2044 infinity | -infinity | timestamp out of range | infinity
2045 infinity | infinity | infinity | timestamp out of range
2048 SELECT i1 AS interval1, i2 AS interval2,
2049 eval(format('interval %L + interval %L', i1, i2)) AS plus,
2050 eval(format('interval %L - interval %L', i1, i2)) AS minus
2051 FROM (VALUES (interval '-infinity'),
2052 (interval '2 months'),
2053 (interval 'infinity')) AS t1(i1),
2054 (VALUES (interval '-infinity'),
2055 (interval '10 days'),
2056 (interval 'infinity')) AS t2(i2);
2057 interval1 | interval2 | plus | minus
2058 -----------+-----------+-----------------------+-----------------------
2059 -infinity | -infinity | -infinity | interval out of range
2060 -infinity | @ 10 days | -infinity | -infinity
2061 -infinity | infinity | interval out of range | -infinity
2062 @ 2 mons | -infinity | -infinity | infinity
2063 @ 2 mons | @ 10 days | @ 2 mons 10 days | @ 2 mons -10 days
2064 @ 2 mons | infinity | infinity | -infinity
2065 infinity | -infinity | interval out of range | infinity
2066 infinity | @ 10 days | infinity | infinity
2067 infinity | infinity | infinity | interval out of range
2070 SELECT interval '2147483646 months 2147483646 days 9223372036854775806 us' + interval '1 month 1 day 1 us';
2071 ERROR: interval out of range
2072 SELECT interval '-2147483647 months -2147483647 days -9223372036854775807 us' + interval '-1 month -1 day -1 us';
2073 ERROR: interval out of range
2074 SELECT interval '2147483646 months 2147483646 days 9223372036854775806 us' - interval '-1 month -1 day -1 us';
2075 ERROR: interval out of range
2076 SELECT interval '-2147483647 months -2147483647 days -9223372036854775807 us' - interval '1 month 1 day 1 us';
2077 ERROR: interval out of range
2078 SELECT t AS timestamp, i AS interval,
2079 eval(format('timestamp %L + interval %L', t, i)) AS plus,
2080 eval(format('timestamp %L - interval %L', t, i)) AS minus
2081 FROM (VALUES (timestamp '-infinity'),
2082 (timestamp '1995-08-06 12:30:15'),
2083 (timestamp 'infinity')) AS t1(t),
2084 (VALUES (interval '-infinity'),
2085 (interval 'infinity')) AS t2(i);
2086 timestamp | interval | plus | minus
2087 ---------------------+-----------+------------------------+------------------------
2088 -infinity | -infinity | -infinity | timestamp out of range
2089 -infinity | infinity | timestamp out of range | -infinity
2090 1995-08-06 12:30:15 | -infinity | -infinity | infinity
2091 1995-08-06 12:30:15 | infinity | infinity | -infinity
2092 infinity | -infinity | timestamp out of range | infinity
2093 infinity | infinity | infinity | timestamp out of range
2096 SELECT t AT TIME ZONE 'GMT' AS timestamptz, i AS interval,
2097 eval(format('timestamptz %L + interval %L', t, i)) AS plus,
2098 eval(format('timestamptz %L - interval %L', t, i)) AS minus
2099 FROM (VALUES (timestamptz '-infinity'),
2100 (timestamptz '1995-08-06 12:30:15 GMT'),
2101 (timestamptz 'infinity')) AS t1(t),
2102 (VALUES (interval '-infinity'),
2103 (interval 'infinity')) AS t2(i);
2104 timestamptz | interval | plus | minus
2105 ---------------------+-----------+------------------------+------------------------
2106 -infinity | -infinity | -infinity | timestamp out of range
2107 -infinity | infinity | timestamp out of range | -infinity
2108 1995-08-06 12:30:15 | -infinity | -infinity | infinity
2109 1995-08-06 12:30:15 | infinity | infinity | -infinity
2110 infinity | -infinity | timestamp out of range | infinity
2111 infinity | infinity | infinity | timestamp out of range
2114 -- time +/- infinite interval not supported
2115 SELECT time '11:27:42' + interval 'infinity';
2116 ERROR: cannot add infinite interval to time
2117 SELECT time '11:27:42' + interval '-infinity';
2118 ERROR: cannot add infinite interval to time
2119 SELECT time '11:27:42' - interval 'infinity';
2120 ERROR: cannot subtract infinite interval from time
2121 SELECT time '11:27:42' - interval '-infinity';
2122 ERROR: cannot subtract infinite interval from time
2123 SELECT timetz '11:27:42' + interval 'infinity';
2124 ERROR: cannot add infinite interval to time
2125 SELECT timetz '11:27:42' + interval '-infinity';
2126 ERROR: cannot add infinite interval to time
2127 SELECT timetz '11:27:42' - interval 'infinity';
2128 ERROR: cannot subtract infinite interval from time
2129 SELECT timetz '11:27:42' - interval '-infinity';
2130 ERROR: cannot subtract infinite interval from time
2133 lhst.i < rhst.i AS lt,
2134 lhst.i <= rhst.i AS le,
2135 lhst.i = rhst.i AS eq,
2136 lhst.i > rhst.i AS gt,
2137 lhst.i >= rhst.i AS ge,
2138 lhst.i <> rhst.i AS ne
2139 FROM INFINITE_INTERVAL_TBL lhst CROSS JOIN INFINITE_INTERVAL_TBL rhst
2140 WHERE NOT isfinite(lhst.i);
2141 lhs | rhs | lt | le | eq | gt | ge | ne
2142 -----------+-------------------------+----+----+----+----+----+----
2143 infinity | infinity | f | t | t | f | t | f
2144 -infinity | infinity | t | t | f | f | f | t
2145 infinity | -infinity | f | f | f | t | t | t
2146 -infinity | -infinity | f | t | t | f | t | f
2147 infinity | @ 1 year 2 days 3 hours | f | f | f | t | t | t
2148 -infinity | @ 1 year 2 days 3 hours | t | t | f | f | f | t
2151 SELECT i AS interval,
2154 i * -2.0 AS mul_neg,
2155 i * 'infinity' AS mul_inf,
2156 i * '-infinity' AS mul_inf_neg,
2159 FROM INFINITE_INTERVAL_TBL
2160 WHERE NOT isfinite(i);
2161 interval | um | mul | mul_neg | mul_inf | mul_inf_neg | div | div_neg
2162 -----------+-----------+-----------+-----------+-----------+-------------+-----------+-----------
2163 infinity | -infinity | infinity | -infinity | infinity | -infinity | infinity | -infinity
2164 -infinity | infinity | -infinity | infinity | -infinity | infinity | -infinity | infinity
2167 SELECT -interval '-2147483647 months -2147483647 days -9223372036854775807 us';
2168 ERROR: interval out of range
2169 SELECT interval 'infinity' * 'nan';
2170 ERROR: interval out of range
2171 SELECT interval '-infinity' * 'nan';
2172 ERROR: interval out of range
2173 SELECT interval '-1073741824 months -1073741824 days -4611686018427387904 us' * 2;
2174 ERROR: interval out of range
2175 SELECT interval 'infinity' * 0;
2176 ERROR: interval out of range
2177 SELECT interval '-infinity' * 0;
2178 ERROR: interval out of range
2179 SELECT interval '0 days' * 'infinity'::float;
2180 ERROR: interval out of range
2181 SELECT interval '0 days' * '-infinity'::float;
2182 ERROR: interval out of range
2183 SELECT interval '5 days' * 'infinity'::float;
2189 SELECT interval '5 days' * '-infinity'::float;
2195 SELECT interval 'infinity' / 'infinity';
2196 ERROR: interval out of range
2197 SELECT interval 'infinity' / '-infinity';
2198 ERROR: interval out of range
2199 SELECT interval 'infinity' / 'nan';
2200 ERROR: interval out of range
2201 SELECT interval '-infinity' / 'infinity';
2202 ERROR: interval out of range
2203 SELECT interval '-infinity' / '-infinity';
2204 ERROR: interval out of range
2205 SELECT interval '-infinity' / 'nan';
2206 ERROR: interval out of range
2207 SELECT interval '-1073741824 months -1073741824 days -4611686018427387904 us' / 0.5;
2208 ERROR: interval out of range
2209 SELECT date_bin('infinity', timestamp '2001-02-16 20:38:40', timestamp '2001-02-16 20:05:00');
2210 ERROR: timestamps cannot be binned into infinite intervals
2211 SELECT date_bin('-infinity', timestamp '2001-02-16 20:38:40', timestamp '2001-02-16 20:05:00');
2212 ERROR: timestamps cannot be binned into infinite intervals
2213 SELECT i AS interval, date_trunc('hour', i)
2214 FROM INFINITE_INTERVAL_TBL
2215 WHERE NOT isfinite(i);
2216 interval | date_trunc
2217 -----------+------------
2219 -infinity | -infinity
2222 SELECT i AS interval, justify_days(i), justify_hours(i), justify_interval(i)
2223 FROM INFINITE_INTERVAL_TBL
2224 WHERE NOT isfinite(i);
2225 interval | justify_days | justify_hours | justify_interval
2226 -----------+--------------+---------------+------------------
2227 infinity | infinity | infinity | infinity
2228 -infinity | -infinity | -infinity | -infinity
2231 SELECT timezone('infinity'::interval, '1995-08-06 12:12:12'::timestamp);
2232 ERROR: interval time zone "infinity" must be finite
2233 SELECT timezone('-infinity'::interval, '1995-08-06 12:12:12'::timestamp);
2234 ERROR: interval time zone "-infinity" must be finite
2235 SELECT timezone('infinity'::interval, '1995-08-06 12:12:12'::timestamptz);
2236 ERROR: interval time zone "infinity" must be finite
2237 SELECT timezone('-infinity'::interval, '1995-08-06 12:12:12'::timestamptz);
2238 ERROR: interval time zone "-infinity" must be finite
2239 SELECT timezone('infinity'::interval, '12:12:12'::time);
2240 ERROR: interval time zone "infinity" must be finite
2241 SELECT timezone('-infinity'::interval, '12:12:12'::time);
2242 ERROR: interval time zone "-infinity" must be finite
2243 SELECT timezone('infinity'::interval, '12:12:12'::timetz);
2244 ERROR: interval time zone "infinity" must be finite
2245 SELECT timezone('-infinity'::interval, '12:12:12'::timetz);
2246 ERROR: interval time zone "-infinity" must be finite
2247 SELECT 'infinity'::interval::time;
2248 ERROR: cannot convert infinite interval to time
2249 SELECT '-infinity'::interval::time;
2250 ERROR: cannot convert infinite interval to time
2251 SELECT to_char('infinity'::interval, 'YYYY');
2257 SELECT to_char('-infinity'::interval, 'YYYY');
2263 -- "ago" can only appear once at the end of an interval.
2264 SELECT INTERVAL '42 days 2 seconds ago ago';
2265 ERROR: invalid input syntax for type interval: "42 days 2 seconds ago ago"
2266 LINE 1: SELECT INTERVAL '42 days 2 seconds ago ago';
2268 SELECT INTERVAL '2 minutes ago 5 days';
2269 ERROR: invalid input syntax for type interval: "2 minutes ago 5 days"
2270 LINE 1: SELECT INTERVAL '2 minutes ago 5 days';
2272 -- consecutive and dangling units are not allowed.
2273 SELECT INTERVAL 'hour 5 months';
2274 ERROR: invalid input syntax for type interval: "hour 5 months"
2275 LINE 1: SELECT INTERVAL 'hour 5 months';
2277 SELECT INTERVAL '1 year months days 5 hours';
2278 ERROR: invalid input syntax for type interval: "1 year months days 5 hours"
2279 LINE 1: SELECT INTERVAL '1 year months days 5 hours';
2281 -- unacceptable reserved words in interval. Only "infinity", "+infinity" and
2282 -- "-infinity" are allowed.
2283 SELECT INTERVAL 'now';
2284 ERROR: invalid input syntax for type interval: "now"
2285 LINE 1: SELECT INTERVAL 'now';
2287 SELECT INTERVAL 'today';
2288 ERROR: invalid input syntax for type interval: "today"
2289 LINE 1: SELECT INTERVAL 'today';
2291 SELECT INTERVAL 'tomorrow';
2292 ERROR: invalid input syntax for type interval: "tomorrow"
2293 LINE 1: SELECT INTERVAL 'tomorrow';
2295 SELECT INTERVAL 'allballs';
2296 ERROR: invalid input syntax for type interval: "allballs"
2297 LINE 1: SELECT INTERVAL 'allballs';
2299 SELECT INTERVAL 'epoch';
2300 ERROR: invalid input syntax for type interval: "epoch"
2301 LINE 1: SELECT INTERVAL 'epoch';
2303 SELECT INTERVAL 'yesterday';
2304 ERROR: invalid input syntax for type interval: "yesterday"
2305 LINE 1: SELECT INTERVAL 'yesterday';
2307 -- infinity specification should be the only thing
2308 SELECT INTERVAL 'infinity years';
2309 ERROR: invalid input syntax for type interval: "infinity years"
2310 LINE 1: SELECT INTERVAL 'infinity years';
2312 SELECT INTERVAL 'infinity ago';
2313 ERROR: invalid input syntax for type interval: "infinity ago"
2314 LINE 1: SELECT INTERVAL 'infinity ago';
2316 SELECT INTERVAL '+infinity -infinity';
2317 ERROR: invalid input syntax for type interval: "+infinity -infinity"
2318 LINE 1: SELECT INTERVAL '+infinity -infinity';