2000-02-06 06:09:42 +01:00
|
|
|
--
|
|
|
|
-- ABSTIME
|
|
|
|
-- testing built-in time type abstime
|
|
|
|
-- uses reltime and tinterval
|
|
|
|
--
|
|
|
|
--
|
|
|
|
-- timezones may vary based not only on location but the operating
|
|
|
|
-- system. the main correctness issue is that the OS may not get
|
|
|
|
-- daylight savings time right for times prior to Unix epoch (jan 1 1970).
|
|
|
|
--
|
|
|
|
CREATE TABLE ABSTIME_TBL (f1 abstime);
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES ('Jan 14, 1973 03:14:21');
|
|
|
|
-- was INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'now'):
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'Mon May 1 00:30:30 1995');
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'epoch');
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'current');
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'infinity');
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime '-infinity');
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'May 10, 1947 23:59:12');
|
|
|
|
-- what happens if we specify slightly misformatted abstime?
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00');
|
|
|
|
ERROR: Bad abstime external representation 'Feb 35, 1946 10:00:00'
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10');
|
|
|
|
ERROR: Bad abstime external representation 'Feb 28, 1984 25:08:10'
|
|
|
|
-- badly formatted abstimes: these should result in invalid abstimes
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format');
|
|
|
|
ERROR: Bad abstime external representation 'bad date format'
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES ('Jun 10, 1843');
|
|
|
|
-- test abstime operators
|
|
|
|
SELECT '' AS eight, ABSTIME_TBL.*;
|
|
|
|
eight | f1
|
|
|
|
-------+------------------------------
|
|
|
|
| Sun Jan 14 03:14:21 1973 PST
|
|
|
|
| Mon May 01 00:30:30 1995 PDT
|
|
|
|
| epoch
|
|
|
|
| current
|
|
|
|
| infinity
|
|
|
|
| -infinity
|
|
|
|
| Sat May 10 23:59:12 1947 PDT
|
|
|
|
| invalid
|
|
|
|
(8 rows)
|
|
|
|
|
|
|
|
SELECT '' AS six, ABSTIME_TBL.*
|
|
|
|
WHERE ABSTIME_TBL.f1 < abstime 'Jun 30, 2001';
|
|
|
|
six | f1
|
|
|
|
-----+------------------------------
|
|
|
|
| Sun Jan 14 03:14:21 1973 PST
|
|
|
|
| Mon May 01 00:30:30 1995 PDT
|
|
|
|
| epoch
|
|
|
|
| current
|
|
|
|
| -infinity
|
|
|
|
| Sat May 10 23:59:12 1947 PDT
|
|
|
|
(6 rows)
|
|
|
|
|
|
|
|
SELECT '' AS six, ABSTIME_TBL.*
|
|
|
|
WHERE ABSTIME_TBL.f1 > abstime '-infinity';
|
|
|
|
six | f1
|
|
|
|
-----+------------------------------
|
|
|
|
| Sun Jan 14 03:14:21 1973 PST
|
|
|
|
| Mon May 01 00:30:30 1995 PDT
|
|
|
|
| epoch
|
|
|
|
| current
|
|
|
|
| infinity
|
|
|
|
| Sat May 10 23:59:12 1947 PDT
|
|
|
|
(6 rows)
|
|
|
|
|
|
|
|
SELECT '' AS six, ABSTIME_TBL.*
|
|
|
|
WHERE abstime 'May 10, 1947 23:59:12' <> ABSTIME_TBL.f1;
|
|
|
|
six | f1
|
|
|
|
-----+------------------------------
|
|
|
|
| Sun Jan 14 03:14:21 1973 PST
|
|
|
|
| Mon May 01 00:30:30 1995 PDT
|
|
|
|
| epoch
|
|
|
|
| current
|
|
|
|
| infinity
|
|
|
|
| -infinity
|
|
|
|
(6 rows)
|
|
|
|
|
|
|
|
SELECT '' AS one, ABSTIME_TBL.*
|
|
|
|
WHERE abstime 'current' = ABSTIME_TBL.f1;
|
|
|
|
one | f1
|
|
|
|
-----+---------
|
|
|
|
| current
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '' AS three, ABSTIME_TBL.*
|
|
|
|
WHERE abstime 'epoch' >= ABSTIME_TBL.f1;
|
|
|
|
three | f1
|
|
|
|
-------+------------------------------
|
|
|
|
| epoch
|
|
|
|
| -infinity
|
|
|
|
| Sat May 10 23:59:12 1947 PDT
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
SELECT '' AS four, ABSTIME_TBL.*
|
|
|
|
WHERE ABSTIME_TBL.f1 <= abstime 'Jan 14, 1973 03:14:21';
|
|
|
|
four | f1
|
|
|
|
------+------------------------------
|
|
|
|
| Sun Jan 14 03:14:21 1973 PST
|
|
|
|
| epoch
|
|
|
|
| -infinity
|
|
|
|
| Sat May 10 23:59:12 1947 PDT
|
|
|
|
(4 rows)
|
|
|
|
|
|
|
|
SELECT '' AS four, ABSTIME_TBL.*
|
|
|
|
WHERE ABSTIME_TBL.f1 <?>
|
|
|
|
tinterval '["Apr 1 1950 00:00:00" "Dec 30 1999 23:00:00"]';
|
|
|
|
four | f1
|
|
|
|
------+------------------------------
|
|
|
|
| Sun Jan 14 03:14:21 1973 PST
|
|
|
|
| Mon May 01 00:30:30 1995 PDT
|
|
|
|
| epoch
|
|
|
|
(3 rows)
|
|
|
|
|
2000-09-14 17:55:07 +02:00
|
|
|
SELECT '' AS four, f1 AS abstime,
|
|
|
|
date_part('year', f1) AS year, date_part('month', f1) AS month,
|
|
|
|
date_part('day',f1) AS day, date_part('hour', f1) AS hour,
|
|
|
|
date_part('minute', f1) AS minute, date_part('second', f1) AS second
|
|
|
|
FROM ABSTIME_TBL
|
|
|
|
WHERE isfinite(f1) and f1 <> abstime 'current'
|
|
|
|
ORDER BY abstime;
|
|
|
|
four | abstime | year | month | day | hour | minute | second
|
|
|
|
------+------------------------------+------+-------+-----+------+--------+--------
|
|
|
|
| Sat May 10 23:59:12 1947 PDT | 1947 | 5 | 10 | 23 | 59 | 12
|
|
|
|
| epoch | 1969 | 12 | 31 | 16 | 0 | 0
|
|
|
|
| Sun Jan 14 03:14:21 1973 PST | 1973 | 1 | 14 | 3 | 14 | 21
|
|
|
|
| Mon May 01 00:30:30 1995 PDT | 1995 | 5 | 1 | 0 | 30 | 30
|
|
|
|
(4 rows)
|
2000-10-23 00:15:13 +02:00
|
|
|
|