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 CREATE TABLE INTERVAL_TBL (f1 interval);
56 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 1 minute');
57 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 5 hour');
58 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 10 day');
59 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 34 year');
60 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 3 months');
61 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 14 seconds ago');
62 INSERT INTO INTERVAL_TBL (f1) VALUES ('1 day 2 hours 3 minutes 4 seconds');
63 INSERT INTO INTERVAL_TBL (f1) VALUES ('6 years');
64 INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months');
65 INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months 12 hours');
66 -- badly formatted interval
67 INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted interval');
68 ERROR: invalid input syntax for type interval: "badly formatted interval"
69 LINE 1: INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted inter...
71 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
72 ERROR: invalid input syntax for type interval: "@ 30 eons ago"
73 LINE 1: INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
75 -- test interval operators
76 SELECT * FROM INTERVAL_TBL;
91 SELECT * FROM INTERVAL_TBL
92 WHERE INTERVAL_TBL.f1 <> interval '@ 10 days';
106 SELECT * FROM INTERVAL_TBL
107 WHERE INTERVAL_TBL.f1 <= interval '@ 5 hours';
115 SELECT * FROM INTERVAL_TBL
116 WHERE INTERVAL_TBL.f1 < interval '@ 1 day';
124 SELECT * FROM INTERVAL_TBL
125 WHERE INTERVAL_TBL.f1 = interval '@ 34 years';
131 SELECT * FROM INTERVAL_TBL
132 WHERE INTERVAL_TBL.f1 >= interval '@ 1 month';
142 SELECT * FROM INTERVAL_TBL
143 WHERE INTERVAL_TBL.f1 > interval '@ 3 seconds ago';
158 FROM INTERVAL_TBL r1, INTERVAL_TBL r2
160 ORDER BY r1.f1, r2.f1;
162 -----------------+-----------------
166 1 day 02:03:04 | -00:00:14
167 1 day 02:03:04 | 00:01:00
168 1 day 02:03:04 | 05:00:00
172 10 days | 1 day 02:03:04
176 3 mons | 1 day 02:03:04
181 5 mons | 1 day 02:03:04
184 5 mons 12:00:00 | -00:00:14
185 5 mons 12:00:00 | 00:01:00
186 5 mons 12:00:00 | 05:00:00
187 5 mons 12:00:00 | 1 day 02:03:04
188 5 mons 12:00:00 | 10 days
189 5 mons 12:00:00 | 3 mons
190 5 mons 12:00:00 | 5 mons
194 6 years | 1 day 02:03:04
198 6 years | 5 mons 12:00:00
202 34 years | 1 day 02:03:04
206 34 years | 5 mons 12:00:00
210 -- Test intervals that are large enough to overflow 64 bits in comparisons
211 CREATE TEMP TABLE INTERVAL_TBL_OF (f1 interval);
212 INSERT INTO INTERVAL_TBL_OF (f1) VALUES
213 ('2147483647 days 2147483647 months'),
214 ('2147483647 days -2147483648 months'),
216 ('-2147483648 days 2147483647 months'),
217 ('-2147483648 days -2147483648 months');
218 -- these should fail as out-of-range
219 INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483648 days');
220 ERROR: interval field value out of range: "2147483648 days"
221 LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483648 days');
223 INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483649 days');
224 ERROR: interval field value out of range: "-2147483649 days"
225 LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483649 days')...
227 INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483647 years');
228 ERROR: interval out of range
229 LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483647 years')...
231 INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483648 years');
232 ERROR: interval out of range
233 LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483648 years'...
235 -- Test edge-case overflow detection in interval multiplication
236 select extract(epoch from '256 microseconds'::interval * (2^55)::float8);
237 ERROR: interval out of range
239 FROM INTERVAL_TBL_OF r1, INTERVAL_TBL_OF r2
241 ORDER BY r1.f1, r2.f1;
243 -------------------------------------------+-------------------------------------------
244 -178956970 years -8 mons +2147483647 days | -178956970 years -8 mons -2147483648 days
245 1 year | -178956970 years -8 mons -2147483648 days
246 1 year | -178956970 years -8 mons +2147483647 days
247 178956970 years 7 mons -2147483648 days | -178956970 years -8 mons -2147483648 days
248 178956970 years 7 mons -2147483648 days | -178956970 years -8 mons +2147483647 days
249 178956970 years 7 mons -2147483648 days | 1 year
250 178956970 years 7 mons 2147483647 days | -178956970 years -8 mons -2147483648 days
251 178956970 years 7 mons 2147483647 days | -178956970 years -8 mons +2147483647 days
252 178956970 years 7 mons 2147483647 days | 1 year
253 178956970 years 7 mons 2147483647 days | 178956970 years 7 mons -2147483648 days
256 CREATE INDEX ON INTERVAL_TBL_OF USING btree (f1);
257 SET enable_seqscan TO false;
259 SELECT f1 FROM INTERVAL_TBL_OF r1 ORDER BY f1;
261 --------------------------------------------------------------------
262 Index Only Scan using interval_tbl_of_f1_idx on interval_tbl_of r1
265 SELECT f1 FROM INTERVAL_TBL_OF r1 ORDER BY f1;
267 -------------------------------------------
268 -178956970 years -8 mons -2147483648 days
269 -178956970 years -8 mons +2147483647 days
271 178956970 years 7 mons -2147483648 days
272 178956970 years 7 mons 2147483647 days
275 RESET enable_seqscan;
276 DROP TABLE INTERVAL_TBL_OF;
277 -- Test multiplication and division with intervals.
278 -- Floating point arithmetic rounding errors can lead to unexpected results,
279 -- though the code attempts to do the right thing and round up to days and
280 -- minutes to avoid results such as '3 days 24:00 hours' or '14:20:60'.
281 -- Note that it is expected for some day components to be greater than 29 and
282 -- some time components be greater than 23:59:59 due to how intervals are
283 -- stored internally.
284 CREATE TABLE INTERVAL_MULDIV_TBL (span interval);
285 COPY INTERVAL_MULDIV_TBL FROM STDIN;
286 SELECT span * 0.3 AS product
287 FROM INTERVAL_MULDIV_TBL;
289 ------------------------------------
290 1 year 12 days 122:24:00
291 -1 years -12 days +93:36:00
293 2 mons 13 days 01:22:28.8
294 -10 mons +120 days 37:28:21.6567
297 24 years 11 mons 320 days 16:48:00
300 SELECT span * 8.2 AS product
301 FROM INTERVAL_MULDIV_TBL;
303 ---------------------------------------------
304 28 years 104 days 2961:36:00
305 -28 years -104 days +2942:24:00
307 6 years 1 mon -197 days +93:34:27.2
308 -24 years -7 mons +3946 days 640:15:11.9498
309 2 years 8 mons 24 days
310 9 years 6 mons 24 days
311 682 years 7 mons 8215 days 19:12:00
314 SELECT span / 10 AS quotient
315 FROM INTERVAL_MULDIV_TBL;
317 ----------------------------------
318 4 mons 4 days 40:48:00
319 -4 mons -4 days +31:12:00
322 -3 mons +30 days 12:29:27.2189
325 8 years 3 mons 126 days 21:36:00
328 SELECT span / 100 AS quotient
329 FROM INTERVAL_MULDIV_TBL;
331 -------------------------
336 -6 days +01:14:56.72189
339 9 mons 39 days 16:33:36
342 DROP TABLE INTERVAL_MULDIV_TBL;
343 SET DATESTYLE = 'postgres';
344 SET IntervalStyle to postgres_verbose;
345 SELECT * FROM INTERVAL_TBL;
347 -------------------------------
354 @ 1 day 2 hours 3 mins 4 secs
360 -- test avg(interval), which is somewhat fragile since people have been
361 -- known to change the allowed input syntax for type interval without
362 -- updating pg_aggregate.agginitval
363 select avg(f1) from interval_tbl;
365 -------------------------------------------------
366 @ 4 years 1 mon 10 days 4 hours 18 mins 23 secs
369 -- test long interval input
370 select '4 millenniums 5 centuries 4 decades 1 year 4 months 4 days 17 minutes 31 seconds'::interval;
372 --------------------------------------------
373 @ 4541 years 4 mons 4 days 17 mins 31 secs
376 -- test long interval output
377 -- Note: the actual maximum length of the interval output is longer,
378 -- but we need the test to work for both integer and floating-point
380 select '100000000y 10mon -1000000000d -100000h -10min -10.000001s ago'::interval;
382 ---------------------------------------------------------------------------------------
383 @ 100000000 years 10 mons -1000000000 days -100000 hours -10 mins -10.000001 secs ago
386 -- test justify_hours() and justify_days()
387 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";
388 6 mons 5 days 4 hours 3 mins 2 seconds
389 ----------------------------------------
390 @ 6 mons 5 days 4 hours 3 mins 2 secs
393 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";
394 7 mons 6 days 5 hours 4 mins 3 seconds
395 ----------------------------------------
396 @ 7 mons 6 days 5 hours 4 mins 3 secs
399 -- test justify_interval()
400 SELECT justify_interval(interval '1 month -1 hour') as "1 month -1 hour";
406 -- test fractional second input, and detection of duplicate units
407 SET DATESTYLE = 'ISO';
408 SET IntervalStyle TO postgres;
409 SELECT '1 millisecond'::interval, '1 microsecond'::interval,
410 '500 seconds 99 milliseconds 51 microseconds'::interval;
411 interval | interval | interval
412 --------------+-----------------+-----------------
413 00:00:00.001 | 00:00:00.000001 | 00:08:20.099051
416 SELECT '3 days 5 milliseconds'::interval;
418 ---------------------
422 SELECT '1 second 2 seconds'::interval; -- error
423 ERROR: invalid input syntax for type interval: "1 second 2 seconds"
424 LINE 1: SELECT '1 second 2 seconds'::interval;
426 SELECT '10 milliseconds 20 milliseconds'::interval; -- error
427 ERROR: invalid input syntax for type interval: "10 milliseconds 20 milliseconds"
428 LINE 1: SELECT '10 milliseconds 20 milliseconds'::interval;
430 SELECT '5.5 seconds 3 milliseconds'::interval; -- error
431 ERROR: invalid input syntax for type interval: "5.5 seconds 3 milliseconds"
432 LINE 1: SELECT '5.5 seconds 3 milliseconds'::interval;
434 SELECT '1:20:05 5 microseconds'::interval; -- error
435 ERROR: invalid input syntax for type interval: "1:20:05 5 microseconds"
436 LINE 1: SELECT '1:20:05 5 microseconds'::interval;
438 SELECT '1 day 1 day'::interval; -- error
439 ERROR: invalid input syntax for type interval: "1 day 1 day"
440 LINE 1: SELECT '1 day 1 day'::interval;
442 SELECT interval '1-2'; -- SQL year-month literal
448 SELECT interval '999' second; -- oversize leading field is ok
454 SELECT interval '999' minute;
460 SELECT interval '999' hour;
466 SELECT interval '999' day;
472 SELECT interval '999' month;
478 -- test SQL-spec syntaxes for restricted field sets
479 SELECT interval '1' year;
485 SELECT interval '2' month;
491 SELECT interval '3' day;
497 SELECT interval '4' hour;
503 SELECT interval '5' minute;
509 SELECT interval '6' second;
515 SELECT interval '1' year to month;
521 SELECT interval '1-2' year to month;
527 SELECT interval '1 2' day to hour;
533 SELECT interval '1 2:03' day to hour;
539 SELECT interval '1 2:03:04' day to hour;
545 SELECT interval '1 2' day to minute;
546 ERROR: invalid input syntax for type interval: "1 2"
547 LINE 1: SELECT interval '1 2' day to minute;
549 SELECT interval '1 2:03' day to minute;
555 SELECT interval '1 2:03:04' day to minute;
561 SELECT interval '1 2' day to second;
562 ERROR: invalid input syntax for type interval: "1 2"
563 LINE 1: SELECT interval '1 2' day to second;
565 SELECT interval '1 2:03' day to second;
571 SELECT interval '1 2:03:04' day to second;
577 SELECT interval '1 2' hour to minute;
578 ERROR: invalid input syntax for type interval: "1 2"
579 LINE 1: SELECT interval '1 2' hour to minute;
581 SELECT interval '1 2:03' hour to minute;
587 SELECT interval '1 2:03:04' hour to minute;
593 SELECT interval '1 2' hour to second;
594 ERROR: invalid input syntax for type interval: "1 2"
595 LINE 1: SELECT interval '1 2' hour to second;
597 SELECT interval '1 2:03' hour to second;
603 SELECT interval '1 2:03:04' hour to second;
609 SELECT interval '1 2' minute to second;
610 ERROR: invalid input syntax for type interval: "1 2"
611 LINE 1: SELECT interval '1 2' minute to second;
613 SELECT interval '1 2:03' minute to second;
619 SELECT interval '1 2:03:04' minute to second;
625 SELECT interval '1 +2:03' minute to second;
631 SELECT interval '1 +2:03:04' minute to second;
637 SELECT interval '1 -2:03' minute to second;
643 SELECT interval '1 -2:03:04' minute to second;
649 SELECT interval '123 11' day to hour; -- ok
655 SELECT interval '123 11' day; -- not ok
656 ERROR: invalid input syntax for type interval: "123 11"
657 LINE 1: SELECT interval '123 11' day;
659 SELECT interval '123 11'; -- not ok, too ambiguous
660 ERROR: invalid input syntax for type interval: "123 11"
661 LINE 1: SELECT interval '123 11';
663 SELECT interval '123 2:03 -2:04'; -- not ok, redundant hh:mm fields
664 ERROR: invalid input syntax for type interval: "123 2:03 -2:04"
665 LINE 1: SELECT interval '123 2:03 -2:04';
667 -- test syntaxes for restricted precision
668 SELECT interval(0) '1 day 01:23:45.6789';
674 SELECT interval(2) '1 day 01:23:45.6789';
680 SELECT interval '12:34.5678' minute to second(2); -- per SQL spec
686 SELECT interval '1.234' second;
692 SELECT interval '1.234' second(2);
698 SELECT interval '1 2.345' day to second(2);
699 ERROR: invalid input syntax for type interval: "1 2.345"
700 LINE 1: SELECT interval '1 2.345' day to second(2);
702 SELECT interval '1 2:03' day to second(2);
708 SELECT interval '1 2:03.4567' day to second(2);
714 SELECT interval '1 2:03:04.5678' day to second(2);
720 SELECT interval '1 2.345' hour to second(2);
721 ERROR: invalid input syntax for type interval: "1 2.345"
722 LINE 1: SELECT interval '1 2.345' hour to second(2);
724 SELECT interval '1 2:03.45678' hour to second(2);
730 SELECT interval '1 2:03:04.5678' hour to second(2);
736 SELECT interval '1 2.3456' minute to second(2);
737 ERROR: invalid input syntax for type interval: "1 2.3456"
738 LINE 1: SELECT interval '1 2.3456' minute to second(2);
740 SELECT interval '1 2:03.5678' minute to second(2);
746 SELECT interval '1 2:03:04.5678' minute to second(2);
752 -- test casting to restricted precision (bug #14479)
753 SELECT f1, f1::INTERVAL DAY TO MINUTE AS "minutes",
754 (f1 + INTERVAL '1 month')::INTERVAL MONTH::INTERVAL YEAR AS "years"
757 -----------------+-----------------+----------
758 00:01:00 | 00:01:00 | 00:00:00
759 05:00:00 | 05:00:00 | 00:00:00
760 10 days | 10 days | 00:00:00
761 34 years | 34 years | 34 years
762 3 mons | 3 mons | 00:00:00
763 -00:00:14 | 00:00:00 | 00:00:00
764 1 day 02:03:04 | 1 day 02:03:00 | 00:00:00
765 6 years | 6 years | 6 years
766 5 mons | 5 mons | 00:00:00
767 5 mons 12:00:00 | 5 mons 12:00:00 | 00:00:00
770 -- test inputting and outputting SQL standard interval literals
771 SET IntervalStyle TO sql_standard;
772 SELECT interval '0' AS "zero",
773 interval '1-2' year to month AS "year-month",
774 interval '1 2:03:04' day to second AS "day-time",
775 - interval '1-2' AS "negative year-month",
776 - interval '1 2:03:04' AS "negative day-time";
777 zero | year-month | day-time | negative year-month | negative day-time
778 ------+------------+-----------+---------------------+-------------------
779 0 | 1-2 | 1 2:03:04 | -1-2 | -1 2:03:04
782 -- test input of some not-quite-standard interval values in the sql style
783 SET IntervalStyle TO postgres;
784 SELECT interval '+1 -1:00:00',
785 interval '-1 +1:00:00',
786 interval '+1-2 -3 +4:05:06.789',
787 interval '-1-2 +3 -4:05:06.789';
788 interval | interval | interval | interval
789 -----------------+-------------------+-------------------------------------+----------------------------------------
790 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
793 -- test output of couple non-standard interval values in the sql style
794 SET IntervalStyle TO sql_standard;
795 SELECT interval '1 day -1 hours',
796 interval '-1 days +1 hours',
797 interval '1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds',
798 - interval '1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds';
799 interval | interval | interval | ?column?
800 ------------------+------------------+----------------------+----------------------
801 +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
804 -- test outputting iso8601 intervals
805 SET IntervalStyle to iso_8601;
806 select interval '0' AS "zero",
807 interval '1-2' AS "a year 2 months",
808 interval '1 2:03:04' AS "a bit over a day",
809 interval '2:03:04.45679' AS "a bit over 2 hours",
810 (interval '1-2' + interval '3 4:05:06.7') AS "all fields",
811 (interval '1-2' - interval '3 4:05:06.7') AS "mixed sign",
812 (- interval '1-2' + interval '3 4:05:06.7') AS "negative";
813 zero | a year 2 months | a bit over a day | a bit over 2 hours | all fields | mixed sign | negative
814 ------+-----------------+------------------+--------------------+------------------+----------------------+--------------------
815 PT0S | P1Y2M | P1DT2H3M4S | PT2H3M4.45679S | P1Y2M3DT4H5M6.7S | P1Y2M-3DT-4H-5M-6.7S | P-1Y-2M3DT4H5M6.7S
818 -- test inputting ISO 8601 4.4.2.1 "Format With Time Unit Designators"
819 SET IntervalStyle to sql_standard;
820 select interval 'P0Y' AS "zero",
821 interval 'P1Y2M' AS "a year 2 months",
822 interval 'P1W' AS "a week",
823 interval 'P1DT2H3M4S' AS "a bit over a day",
824 interval 'P1Y2M3DT4H5M6.7S' AS "all fields",
825 interval 'P-1Y-2M-3DT-4H-5M-6.7S' AS "negative",
826 interval 'PT-0.1S' AS "fractional second";
827 zero | a year 2 months | a week | a bit over a day | all fields | negative | fractional second
828 ------+-----------------+-----------+------------------+--------------------+--------------------+-------------------
829 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
832 -- test inputting ISO 8601 4.4.2.2 "Alternative Format"
833 SET IntervalStyle to postgres;
834 select interval 'P00021015T103020' AS "ISO8601 Basic Format",
835 interval 'P0002-10-15T10:30:20' AS "ISO8601 Extended Format";
836 ISO8601 Basic Format | ISO8601 Extended Format
837 ----------------------------------+----------------------------------
838 2 years 10 mons 15 days 10:30:20 | 2 years 10 mons 15 days 10:30:20
841 -- Make sure optional ISO8601 alternative format fields are optional.
842 select interval 'P0002' AS "year only",
843 interval 'P0002-10' AS "year month",
844 interval 'P0002-10-15' AS "year month day",
845 interval 'P0002T1S' AS "year only plus time",
846 interval 'P0002-10T1S' AS "year month plus time",
847 interval 'P0002-10-15T1S' AS "year month day plus time",
848 interval 'PT10' AS "hour only",
849 interval 'PT10:30' AS "hour minute";
850 year only | year month | year month day | year only plus time | year month plus time | year month day plus time | hour only | hour minute
851 -----------+-----------------+-------------------------+---------------------+--------------------------+----------------------------------+-----------+-------------
852 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
855 -- test a couple rounding cases that changed since 8.3 w/ HAVE_INT64_TIMESTAMP.
856 SET IntervalStyle to postgres_verbose;
857 select interval '-10 mons -3 days +03:55:06.70';
859 --------------------------------------------------
860 @ 10 mons 3 days -3 hours -55 mins -6.7 secs ago
863 select interval '1 year 2 mons 3 days 04:05:06.699999';
865 -----------------------------------------------------
866 @ 1 year 2 mons 3 days 4 hours 5 mins 6.699999 secs
869 select interval '0:0:0.7', interval '@ 0.70 secs', interval '0.7 seconds';
870 interval | interval | interval
871 ------------+------------+------------
872 @ 0.7 secs | @ 0.7 secs | @ 0.7 secs
875 -- check that '30 days' equals '1 month' according to the hash function
876 select '30 days'::interval = '1 month'::interval as t;
882 select interval_hash('30 days'::interval) = interval_hash('1 month'::interval) as t;
888 -- numeric constructor
889 select make_interval(years := 2);
895 select make_interval(years := 1, months := 6);
901 select make_interval(years := 1, months := -1, weeks := 5, days := -7, hours := 25, mins := -180);
903 ----------------------------
904 @ 11 mons 28 days 22 hours
907 select make_interval() = make_interval(years := 0, months := 0, weeks := 0, days := 0, mins := 0, secs := 0.0);
913 select make_interval(hours := -2, mins := -10, secs := -25.3);
915 ---------------------------------
916 @ 2 hours 10 mins 25.3 secs ago
919 select make_interval(years := 'inf'::float::int);
920 ERROR: integer out of range
921 select make_interval(months := 'NaN'::float::int);
922 ERROR: integer out of range
923 select make_interval(secs := 'inf');
924 ERROR: interval out of range
925 select make_interval(secs := 'NaN');
926 ERROR: interval out of range
927 select make_interval(secs := 7e12);
929 ------------------------------------
930 @ 1944444444 hours 26 mins 40 secs
937 EXTRACT(MICROSECOND FROM f1) AS MICROSECOND,
938 EXTRACT(MILLISECOND FROM f1) AS MILLISECOND,
939 EXTRACT(SECOND FROM f1) AS SECOND,
940 EXTRACT(MINUTE FROM f1) AS MINUTE,
941 EXTRACT(HOUR FROM f1) AS HOUR,
942 EXTRACT(DAY FROM f1) AS DAY,
943 EXTRACT(MONTH FROM f1) AS MONTH,
944 EXTRACT(QUARTER FROM f1) AS QUARTER,
945 EXTRACT(YEAR FROM f1) AS YEAR,
946 EXTRACT(DECADE FROM f1) AS DECADE,
947 EXTRACT(CENTURY FROM f1) AS CENTURY,
948 EXTRACT(MILLENNIUM FROM f1) AS MILLENNIUM,
949 EXTRACT(EPOCH FROM f1) AS EPOCH
951 f1 | microsecond | millisecond | second | minute | hour | day | month | quarter | year | decade | century | millennium | epoch
952 -------------------------------+-------------+-------------+------------+--------+------+-----+-------+---------+------+--------+---------+------------+-------------------
953 @ 1 min | 0 | 0.000 | 0.000000 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 60.000000
954 @ 5 hours | 0 | 0.000 | 0.000000 | 0 | 5 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 18000.000000
955 @ 10 days | 0 | 0.000 | 0.000000 | 0 | 0 | 10 | 0 | 1 | 0 | 0 | 0 | 0 | 864000.000000
956 @ 34 years | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 1 | 34 | 3 | 0 | 0 | 1072224000.000000
957 @ 3 mons | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 3 | 2 | 0 | 0 | 0 | 0 | 7776000.000000
958 @ 14 secs ago | -14000000 | -14000.000 | -14.000000 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | -14.000000
959 @ 1 day 2 hours 3 mins 4 secs | 4000000 | 4000.000 | 4.000000 | 3 | 2 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 93784.000000
960 @ 6 years | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 0 | 1 | 6 | 0 | 0 | 0 | 189216000.000000
961 @ 5 mons | 0 | 0.000 | 0.000000 | 0 | 0 | 0 | 5 | 2 | 0 | 0 | 0 | 0 | 12960000.000000
962 @ 5 mons 12 hours | 0 | 0.000 | 0.000000 | 0 | 12 | 0 | 5 | 2 | 0 | 0 | 0 | 0 | 13003200.000000
965 SELECT EXTRACT(FORTNIGHT FROM INTERVAL '2 days'); -- error
966 ERROR: interval units "fortnight" not recognized
967 SELECT EXTRACT(TIMEZONE FROM INTERVAL '2 days'); -- error
968 ERROR: interval units "timezone" not supported
969 SELECT EXTRACT(DECADE FROM INTERVAL '100 y');
975 SELECT EXTRACT(DECADE FROM INTERVAL '99 y');
981 SELECT EXTRACT(DECADE FROM INTERVAL '-99 y');
987 SELECT EXTRACT(DECADE FROM INTERVAL '-100 y');
993 SELECT EXTRACT(CENTURY FROM INTERVAL '100 y');
999 SELECT EXTRACT(CENTURY FROM INTERVAL '99 y');
1005 SELECT EXTRACT(CENTURY FROM INTERVAL '-99 y');
1011 SELECT EXTRACT(CENTURY FROM INTERVAL '-100 y');
1017 -- date_part implementation is mostly the same as extract, so only
1018 -- test a few cases for additional coverage.
1020 date_part('microsecond', f1) AS microsecond,
1021 date_part('millisecond', f1) AS millisecond,
1022 date_part('second', f1) AS second,
1023 date_part('epoch', f1) AS epoch
1025 f1 | microsecond | millisecond | second | epoch
1026 -------------------------------+-------------+-------------+--------+------------
1027 @ 1 min | 0 | 0 | 0 | 60
1028 @ 5 hours | 0 | 0 | 0 | 18000
1029 @ 10 days | 0 | 0 | 0 | 864000
1030 @ 34 years | 0 | 0 | 0 | 1072958400
1031 @ 3 mons | 0 | 0 | 0 | 7776000
1032 @ 14 secs ago | -14000000 | -14000 | -14 | -14
1033 @ 1 day 2 hours 3 mins 4 secs | 4000000 | 4000 | 4 | 93784
1034 @ 6 years | 0 | 0 | 0 | 189345600
1035 @ 5 mons | 0 | 0 | 0 | 12960000
1036 @ 5 mons 12 hours | 0 | 0 | 0 | 13003200
1039 -- internal overflow test case
1040 SELECT extract(epoch from interval '1000000000 days');
1042 -----------------------
1043 86400000000000.000000