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)
|
|
|
|
|
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)
|
|
|
|
|
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
|
|
|
|
-------------------------------------------------
|
2005-10-25 19:13:07 +02:00
|
|
|
@ 4 years 1 mon 9 days 28 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)
|
|
|
|
|