2000-01-05 07:06:23 +01:00
|
|
|
--
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:27:27 +01:00
|
|
|
-- INTERVAL
|
2000-01-05 07:06:23 +01:00
|
|
|
--
|
2003-04-18 00:26:02 +02:00
|
|
|
SET DATESTYLE = 'ISO';
|
2000-11-06 17:03:47 +01:00
|
|
|
-- check acceptance of "time zone style"
|
2000-11-11 20:56:43 +01:00
|
|
|
SELECT INTERVAL '01:00' AS "One hour";
|
|
|
|
One hour
|
2000-11-06 17:03:47 +01:00
|
|
|
----------
|
2003-06-25 23:14:15 +02:00
|
|
|
01:00:00
|
2000-11-06 17:03:47 +01:00
|
|
|
(1 row)
|
|
|
|
|
2000-11-11 20:56:43 +01:00
|
|
|
SELECT INTERVAL '+02:00' AS "Two hours";
|
|
|
|
Two hours
|
|
|
|
-----------
|
2003-06-25 23:14:15 +02:00
|
|
|
02:00:00
|
2000-11-06 17:03:47 +01:00
|
|
|
(1 row)
|
|
|
|
|
2000-11-11 20:56:43 +01:00
|
|
|
SELECT INTERVAL '-08:00' AS "Eight hours";
|
|
|
|
Eight hours
|
|
|
|
-------------
|
2003-06-25 23:14:15 +02:00
|
|
|
-08:00:00
|
2000-11-06 17:03:47 +01:00
|
|
|
(1 row)
|
|
|
|
|
2000-11-11 20:56:43 +01:00
|
|
|
SELECT INTERVAL '-05' AS "Five hours";
|
|
|
|
Five hours
|
|
|
|
------------
|
2003-06-25 23:14:15 +02:00
|
|
|
-05:00:00
|
2000-11-06 17:03:47 +01:00
|
|
|
(1 row)
|
|
|
|
|
2000-11-11 20:56:43 +01:00
|
|
|
SELECT INTERVAL '-1 +02:03' AS "22 hours ago...";
|
2005-07-20 18:42:32 +02:00
|
|
|
22 hours ago...
|
|
|
|
-------------------
|
|
|
|
-1 days +02:03:00
|
2000-11-06 17:03:47 +01:00
|
|
|
(1 row)
|
|
|
|
|
2000-11-11 20:56:43 +01:00
|
|
|
SELECT INTERVAL '-1 days +02:03' AS "22 hours ago...";
|
2005-07-20 18:42:32 +02:00
|
|
|
22 hours ago...
|
|
|
|
-------------------
|
|
|
|
-1 days +02:03:00
|
2000-11-06 17:03:47 +01:00
|
|
|
(1 row)
|
|
|
|
|
2006-09-04 03:26:28 +02:00
|
|
|
SELECT INTERVAL '1.5 weeks' AS "Ten days twelve hours";
|
|
|
|
Ten days twelve hours
|
|
|
|
-----------------------
|
|
|
|
10 days 12:00:00
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT INTERVAL '1.5 months' AS "One month 15 days";
|
|
|
|
One month 15 days
|
|
|
|
-------------------
|
|
|
|
1 mon 15 days
|
|
|
|
(1 row)
|
|
|
|
|
2000-11-11 20:56:43 +01:00
|
|
|
SELECT INTERVAL '10 years -11 month -12 days +13:14' AS "9 years...";
|
2003-06-25 23:14:15 +02:00
|
|
|
9 years...
|
|
|
|
----------------------------------
|
2005-07-20 18:42:32 +02:00
|
|
|
9 years 1 mon -12 days +13:14:00
|
2000-11-06 17:03:47 +01:00
|
|
|
(1 row)
|
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:27:27 +01:00
|
|
|
CREATE TABLE INTERVAL_TBL (f1 interval);
|
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 1 minute');
|
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 5 hour');
|
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 10 day');
|
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 34 year');
|
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 3 months');
|
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 14 seconds ago');
|
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('1 day 2 hours 3 minutes 4 seconds');
|
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('6 years');
|
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months');
|
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months 12 hours');
|
|
|
|
-- badly formatted interval
|
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted interval');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: invalid input syntax for type interval: "badly formatted interval"
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:27:27 +01:00
|
|
|
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: invalid input syntax for type interval: "@ 30 eons ago"
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:27:27 +01:00
|
|
|
-- test interval operators
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS ten, * FROM INTERVAL_TBL;
|
2003-06-25 23:14:15 +02:00
|
|
|
ten | f1
|
|
|
|
-----+-----------------
|
|
|
|
| 00:01:00
|
|
|
|
| 05:00:00
|
2001-01-18 08:22:43 +01:00
|
|
|
| 10 days
|
|
|
|
| 34 years
|
|
|
|
| 3 mons
|
2000-11-06 17:03:47 +01:00
|
|
|
| -00:00:14
|
2001-01-18 08:22:43 +01:00
|
|
|
| 1 day 02:03:04
|
|
|
|
| 6 years
|
|
|
|
| 5 mons
|
2003-06-25 23:14:15 +02:00
|
|
|
| 5 mons 12:00:00
|
1997-04-27 05:57:34 +02:00
|
|
|
(10 rows)
|
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS nine, * FROM INTERVAL_TBL
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:27:27 +01:00
|
|
|
WHERE INTERVAL_TBL.f1 <> interval '@ 10 days';
|
2003-06-25 23:14:15 +02:00
|
|
|
nine | f1
|
|
|
|
------+-----------------
|
|
|
|
| 00:01:00
|
|
|
|
| 05:00:00
|
2001-01-18 08:22:43 +01:00
|
|
|
| 34 years
|
|
|
|
| 3 mons
|
2000-11-06 17:03:47 +01:00
|
|
|
| -00:00:14
|
2001-01-18 08:22:43 +01:00
|
|
|
| 1 day 02:03:04
|
|
|
|
| 6 years
|
|
|
|
| 5 mons
|
2003-06-25 23:14:15 +02:00
|
|
|
| 5 mons 12:00:00
|
1997-04-27 05:57:34 +02:00
|
|
|
(9 rows)
|
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS three, * FROM INTERVAL_TBL
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:27:27 +01:00
|
|
|
WHERE INTERVAL_TBL.f1 <= interval '@ 5 hours';
|
2000-11-06 17:03:47 +01:00
|
|
|
three | f1
|
|
|
|
-------+-----------
|
2003-06-25 23:14:15 +02:00
|
|
|
| 00:01:00
|
|
|
|
| 05:00:00
|
2000-11-06 17:03:47 +01:00
|
|
|
| -00:00:14
|
1997-04-27 05:57:34 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS three, * FROM INTERVAL_TBL
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:27:27 +01:00
|
|
|
WHERE INTERVAL_TBL.f1 < interval '@ 1 day';
|
2000-11-06 17:03:47 +01:00
|
|
|
three | f1
|
|
|
|
-------+-----------
|
2003-06-25 23:14:15 +02:00
|
|
|
| 00:01:00
|
|
|
|
| 05:00:00
|
2000-11-06 17:03:47 +01:00
|
|
|
| -00:00:14
|
1997-04-27 05:57:34 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS one, * FROM INTERVAL_TBL
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:27:27 +01:00
|
|
|
WHERE INTERVAL_TBL.f1 = interval '@ 34 years';
|
2001-01-18 08:22:43 +01:00
|
|
|
one | f1
|
|
|
|
-----+----------
|
|
|
|
| 34 years
|
1997-04-27 05:57:34 +02:00
|
|
|
(1 row)
|
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS five, * FROM INTERVAL_TBL
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:27:27 +01:00
|
|
|
WHERE INTERVAL_TBL.f1 >= interval '@ 1 month';
|
2003-06-25 23:14:15 +02:00
|
|
|
five | f1
|
|
|
|
------+-----------------
|
2001-01-18 08:22:43 +01:00
|
|
|
| 34 years
|
|
|
|
| 3 mons
|
|
|
|
| 6 years
|
|
|
|
| 5 mons
|
2003-06-25 23:14:15 +02:00
|
|
|
| 5 mons 12:00:00
|
1997-04-27 05:57:34 +02:00
|
|
|
(5 rows)
|
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS nine, * FROM INTERVAL_TBL
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:27:27 +01:00
|
|
|
WHERE INTERVAL_TBL.f1 > interval '@ 3 seconds ago';
|
2003-06-25 23:14:15 +02:00
|
|
|
nine | f1
|
|
|
|
------+-----------------
|
|
|
|
| 00:01:00
|
|
|
|
| 05:00:00
|
2001-01-18 08:22:43 +01:00
|
|
|
| 10 days
|
|
|
|
| 34 years
|
|
|
|
| 3 mons
|
|
|
|
| 1 day 02:03:04
|
|
|
|
| 6 years
|
|
|
|
| 5 mons
|
2003-06-25 23:14:15 +02:00
|
|
|
| 5 mons 12:00:00
|
1997-04-27 05:57:34 +02:00
|
|
|
(9 rows)
|
|
|
|
|
2000-01-05 07:06:23 +01:00
|
|
|
SELECT '' AS fortyfive, r1.*, r2.*
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:27:27 +01:00
|
|
|
FROM INTERVAL_TBL r1, INTERVAL_TBL r2
|
1997-05-09 05:26:56 +02:00
|
|
|
WHERE r1.f1 > r2.f1
|
|
|
|
ORDER BY r1.f1, r2.f1;
|
2003-06-25 23:14:15 +02:00
|
|
|
fortyfive | f1 | f1
|
|
|
|
-----------+-----------------+-----------------
|
|
|
|
| 00:01:00 | -00:00:14
|
|
|
|
| 05:00:00 | -00:00:14
|
|
|
|
| 05:00:00 | 00:01:00
|
|
|
|
| 1 day 02:03:04 | -00:00:14
|
|
|
|
| 1 day 02:03:04 | 00:01:00
|
|
|
|
| 1 day 02:03:04 | 05:00:00
|
|
|
|
| 10 days | -00:00:14
|
|
|
|
| 10 days | 00:01:00
|
|
|
|
| 10 days | 05:00:00
|
|
|
|
| 10 days | 1 day 02:03:04
|
|
|
|
| 3 mons | -00:00:14
|
|
|
|
| 3 mons | 00:01:00
|
|
|
|
| 3 mons | 05:00:00
|
|
|
|
| 3 mons | 1 day 02:03:04
|
|
|
|
| 3 mons | 10 days
|
|
|
|
| 5 mons | -00:00:14
|
|
|
|
| 5 mons | 00:01:00
|
|
|
|
| 5 mons | 05:00:00
|
|
|
|
| 5 mons | 1 day 02:03:04
|
|
|
|
| 5 mons | 10 days
|
|
|
|
| 5 mons | 3 mons
|
|
|
|
| 5 mons 12:00:00 | -00:00:14
|
|
|
|
| 5 mons 12:00:00 | 00:01:00
|
|
|
|
| 5 mons 12:00:00 | 05:00:00
|
|
|
|
| 5 mons 12:00:00 | 1 day 02:03:04
|
|
|
|
| 5 mons 12:00:00 | 10 days
|
|
|
|
| 5 mons 12:00:00 | 3 mons
|
|
|
|
| 5 mons 12:00:00 | 5 mons
|
|
|
|
| 6 years | -00:00:14
|
|
|
|
| 6 years | 00:01:00
|
|
|
|
| 6 years | 05:00:00
|
|
|
|
| 6 years | 1 day 02:03:04
|
|
|
|
| 6 years | 10 days
|
|
|
|
| 6 years | 3 mons
|
|
|
|
| 6 years | 5 mons
|
|
|
|
| 6 years | 5 mons 12:00:00
|
|
|
|
| 34 years | -00:00:14
|
|
|
|
| 34 years | 00:01:00
|
|
|
|
| 34 years | 05:00:00
|
|
|
|
| 34 years | 1 day 02:03:04
|
|
|
|
| 34 years | 10 days
|
|
|
|
| 34 years | 3 mons
|
|
|
|
| 34 years | 5 mons
|
|
|
|
| 34 years | 5 mons 12:00:00
|
|
|
|
| 34 years | 6 years
|
1997-04-27 05:57:34 +02:00
|
|
|
(45 rows)
|
|
|
|
|
2006-09-06 04:05:41 +02:00
|
|
|
-- Test multiplication and division with intervals.
|
|
|
|
-- Floating point arithmetic rounding errors can lead to unexpected results,
|
|
|
|
-- though the code attempts to do the right thing and round up to days and
|
|
|
|
-- minutes to avoid results such as '3 days 24:00 hours' or '14:20:60'.
|
|
|
|
-- Note that it is expected for some day components to be greater than 29 and
|
|
|
|
-- some time components be greater than 23:59:59 due to how intervals are
|
|
|
|
-- stored internally.
|
|
|
|
CREATE TABLE INTERVAL_MULDIV_TBL (span interval);
|
|
|
|
COPY INTERVAL_MULDIV_TBL FROM STDIN;
|
|
|
|
SELECT span * 0.3 AS product
|
|
|
|
FROM INTERVAL_MULDIV_TBL;
|
|
|
|
product
|
|
|
|
------------------------------------
|
|
|
|
1 year 12 days 122:24:00
|
|
|
|
-1 years -12 days +93:36:00
|
|
|
|
-3 days -14:24:00
|
|
|
|
2 mons 13 days 01:22:28.80
|
|
|
|
-10 mons +120 days 37:28:21.6567
|
|
|
|
1 mon 6 days
|
|
|
|
4 mons 6 days
|
|
|
|
24 years 11 mons 320 days 16:48:00
|
|
|
|
(8 rows)
|
|
|
|
|
|
|
|
SELECT span * 8.2 AS product
|
|
|
|
FROM INTERVAL_MULDIV_TBL;
|
|
|
|
product
|
|
|
|
---------------------------------------------
|
|
|
|
28 years 104 days 2961:36:00
|
|
|
|
-28 years -104 days +2942:24:00
|
|
|
|
-98 days -09:36:00
|
|
|
|
6 years 1 mon -197 days +93:34:27.20
|
|
|
|
-24 years -7 mons +3946 days 640:15:11.9498
|
|
|
|
2 years 8 mons 24 days
|
|
|
|
9 years 6 mons 24 days
|
|
|
|
682 years 7 mons 8215 days 19:12:00
|
|
|
|
(8 rows)
|
|
|
|
|
|
|
|
SELECT span / 10 AS quotient
|
|
|
|
FROM INTERVAL_MULDIV_TBL;
|
|
|
|
quotient
|
|
|
|
----------------------------------
|
|
|
|
4 mons 4 days 40:48:00
|
|
|
|
-4 mons -4 days +31:12:00
|
|
|
|
-1 days -04:48:00
|
|
|
|
25 days -15:32:30.40
|
|
|
|
-3 mons +30 days 12:29:27.2189
|
|
|
|
12 days
|
|
|
|
1 mon 12 days
|
|
|
|
8 years 3 mons 126 days 21:36:00
|
|
|
|
(8 rows)
|
|
|
|
|
|
|
|
SELECT span / 100 AS quotient
|
|
|
|
FROM INTERVAL_MULDIV_TBL;
|
|
|
|
quotient
|
|
|
|
-------------------------
|
|
|
|
12 days 13:40:48
|
|
|
|
-12 days -06:28:48
|
|
|
|
-02:52:48
|
|
|
|
2 days 10:26:44.96
|
|
|
|
-6 days +01:14:56.72189
|
|
|
|
1 day 04:48:00
|
|
|
|
4 days 04:48:00
|
|
|
|
9 mons 39 days 16:33:36
|
|
|
|
(8 rows)
|
|
|
|
|
|
|
|
DROP TABLE INTERVAL_MULDIV_TBL;
|
2000-11-06 17:03:47 +01:00
|
|
|
SET DATESTYLE = 'postgres';
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS ten, * FROM INTERVAL_TBL;
|
2000-11-06 17:03:47 +01:00
|
|
|
ten | f1
|
|
|
|
-----+-------------------------------
|
|
|
|
| @ 1 min
|
|
|
|
| @ 5 hours
|
|
|
|
| @ 10 days
|
|
|
|
| @ 34 years
|
|
|
|
| @ 3 mons
|
|
|
|
| @ 14 secs ago
|
|
|
|
| @ 1 day 2 hours 3 mins 4 secs
|
|
|
|
| @ 6 years
|
|
|
|
| @ 5 mons
|
|
|
|
| @ 5 mons 12 hours
|
|
|
|
(10 rows)
|
|
|
|
|
2001-05-18 18:02:01 +02:00
|
|
|
-- test avg(interval), which is somewhat fragile since people have been
|
|
|
|
-- known to change the allowed input syntax for type interval without
|
|
|
|
-- updating pg_aggregate.agginitval
|
|
|
|
select avg(f1) from interval_tbl;
|
|
|
|
avg
|
|
|
|
-------------------------------------------------
|
2006-09-03 05:34:04 +02:00
|
|
|
@ 4 years 1 mon 10 days 4 hours 18 mins 23 secs
|
2001-05-18 18:02:01 +02:00
|
|
|
(1 row)
|
|
|
|
|
2005-05-26 04:04:14 +02:00
|
|
|
-- test long interval input
|
|
|
|
select '4 millenniums 5 centuries 4 decades 1 year 4 months 4 days 17 minutes 31 seconds'::interval;
|
|
|
|
interval
|
|
|
|
--------------------------------------------
|
|
|
|
@ 4541 years 4 mons 4 days 17 mins 31 secs
|
|
|
|
(1 row)
|
|
|
|
|
2005-07-30 16:52:04 +02:00
|
|
|
-- test justify_hours() and justify_days()
|
|
|
|
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";
|
|
|
|
6 mons 5 days 4 hours 3 mins 2 seconds
|
|
|
|
----------------------------------------
|
|
|
|
@ 6 mons 5 days 4 hours 3 mins 2 secs
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
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";
|
|
|
|
7 mons 6 days 5 hours 4 mins 3 seconds
|
|
|
|
----------------------------------------
|
|
|
|
@ 7 mons 6 days 5 hours 4 mins 3 secs
|
|
|
|
(1 row)
|
|
|
|
|
2006-03-06 23:49:17 +01:00
|
|
|
-- test justify_interval()
|
|
|
|
SELECT justify_interval(interval '1 month -1 hour') as "1 month -1 hour";
|
|
|
|
1 month -1 hour
|
|
|
|
--------------------
|
|
|
|
@ 29 days 23 hours
|
|
|
|
(1 row)
|
|
|
|
|
2007-05-29 06:58:43 +02:00
|
|
|
-- test fractional second input, and detection of duplicate units
|
|
|
|
SET DATESTYLE = 'ISO';
|
|
|
|
SELECT '1 millisecond'::interval, '1 microsecond'::interval,
|
|
|
|
'500 seconds 99 milliseconds 51 microseconds'::interval;
|
|
|
|
interval | interval | interval
|
|
|
|
--------------+-----------------+-----------------
|
|
|
|
00:00:00.001 | 00:00:00.000001 | 00:08:20.099051
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '3 days 5 milliseconds'::interval;
|
|
|
|
interval
|
|
|
|
---------------------
|
|
|
|
3 days 00:00:00.005
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '1 second 2 seconds'::interval; -- error
|
|
|
|
ERROR: invalid input syntax for type interval: "1 second 2 seconds"
|
|
|
|
SELECT '10 milliseconds 20 milliseconds'::interval; -- error
|
|
|
|
ERROR: invalid input syntax for type interval: "10 milliseconds 20 milliseconds"
|
|
|
|
SELECT '5.5 seconds 3 milliseconds'::interval; -- error
|
|
|
|
ERROR: invalid input syntax for type interval: "5.5 seconds 3 milliseconds"
|
|
|
|
SELECT '1:20:05 5 microseconds'::interval; -- error
|
|
|
|
ERROR: invalid input syntax for type interval: "1:20:05 5 microseconds"
|