2000-01-05 07:06:23 +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);
|
2001-09-28 10:00:11 +02:00
|
|
|
BEGIN;
|
2001-11-21 19:27:25 +01:00
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'now');
|
2001-09-28 10:00:11 +02:00
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'now');
|
|
|
|
SELECT count(*) AS two FROM ABSTIME_TBL WHERE f1 = 'now' ;
|
|
|
|
two
|
|
|
|
-----
|
|
|
|
2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
END;
|
|
|
|
DELETE FROM ABSTIME_TBL;
|
2000-01-05 07:06:23 +01:00
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES ('Jan 14, 1973 03:14:21');
|
|
|
|
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 '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');
|
2003-08-28 01:29:29 +02:00
|
|
|
ERROR: date/time field value out of range: "Feb 35, 1946 10:00:00"
|
2003-09-25 08:58:07 +02:00
|
|
|
HINT: Perhaps you need a different "datestyle" setting.
|
2000-01-05 07:06:23 +01:00
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10');
|
2003-08-28 01:29:29 +02:00
|
|
|
ERROR: date/time field value out of range: "Feb 28, 1984 25:08:10"
|
2000-01-05 07:06:23 +01:00
|
|
|
-- badly formatted abstimes: these should result in invalid abstimes
|
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: invalid input syntax for type abstime: "bad date format"
|
2000-01-05 07:06:23 +01:00
|
|
|
INSERT INTO ABSTIME_TBL (f1) VALUES ('Jun 10, 1843');
|
|
|
|
-- test abstime operators
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS eight, * FROM ABSTIME_TBL;
|
2000-01-05 07:06:23 +01:00
|
|
|
eight | f1
|
|
|
|
-------+------------------------------
|
|
|
|
| Sun Jan 14 03:14:21 1973 PST
|
|
|
|
| Mon May 01 00:30:30 1995 PDT
|
2001-09-28 10:00:11 +02:00
|
|
|
| Wed Dec 31 16:00:00 1969 PST
|
2000-01-05 07:06:23 +01:00
|
|
|
| infinity
|
|
|
|
| -infinity
|
|
|
|
| Sat May 10 23:59:12 1947 PST
|
|
|
|
| invalid
|
2001-09-28 10:00:11 +02:00
|
|
|
(7 rows)
|
1997-04-05 13:06:04 +02:00
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS six, * FROM ABSTIME_TBL
|
2000-01-05 07:06:23 +01:00
|
|
|
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
|
2001-09-28 10:00:11 +02:00
|
|
|
| Wed Dec 31 16:00:00 1969 PST
|
2000-01-05 07:06:23 +01:00
|
|
|
| -infinity
|
|
|
|
| Sat May 10 23:59:12 1947 PST
|
2001-07-02 21:31:52 +02:00
|
|
|
(5 rows)
|
1997-04-05 13:06:04 +02:00
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS six, * FROM ABSTIME_TBL
|
2000-01-05 07:06:23 +01:00
|
|
|
WHERE ABSTIME_TBL.f1 > abstime '-infinity';
|
|
|
|
six | f1
|
|
|
|
-----+------------------------------
|
|
|
|
| Sun Jan 14 03:14:21 1973 PST
|
|
|
|
| Mon May 01 00:30:30 1995 PDT
|
2001-09-28 10:00:11 +02:00
|
|
|
| Wed Dec 31 16:00:00 1969 PST
|
2000-01-05 07:06:23 +01:00
|
|
|
| infinity
|
|
|
|
| Sat May 10 23:59:12 1947 PST
|
2001-05-03 21:00:37 +02:00
|
|
|
| invalid
|
2001-09-28 10:00:11 +02:00
|
|
|
(6 rows)
|
1997-04-05 13:06:04 +02:00
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS six, * FROM ABSTIME_TBL
|
2000-01-05 07:06:23 +01:00
|
|
|
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
|
2001-09-28 10:00:11 +02:00
|
|
|
| Wed Dec 31 16:00:00 1969 PST
|
2000-01-05 07:06:23 +01:00
|
|
|
| infinity
|
|
|
|
| -infinity
|
2001-05-03 21:00:37 +02:00
|
|
|
| invalid
|
2001-09-28 10:00:11 +02:00
|
|
|
(6 rows)
|
1997-04-27 04:58:38 +02:00
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS three, * FROM ABSTIME_TBL
|
2000-01-05 07:06:23 +01:00
|
|
|
WHERE abstime 'epoch' >= ABSTIME_TBL.f1;
|
|
|
|
three | f1
|
|
|
|
-------+------------------------------
|
2001-09-28 10:00:11 +02:00
|
|
|
| Wed Dec 31 16:00:00 1969 PST
|
2000-01-05 07:06:23 +01:00
|
|
|
| -infinity
|
|
|
|
| Sat May 10 23:59:12 1947 PST
|
1997-04-27 04:58:38 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS four, * FROM ABSTIME_TBL
|
2000-01-05 07:06:23 +01:00
|
|
|
WHERE ABSTIME_TBL.f1 <= abstime 'Jan 14, 1973 03:14:21';
|
|
|
|
four | f1
|
|
|
|
------+------------------------------
|
|
|
|
| Sun Jan 14 03:14:21 1973 PST
|
2001-09-28 10:00:11 +02:00
|
|
|
| Wed Dec 31 16:00:00 1969 PST
|
2000-01-05 07:06:23 +01:00
|
|
|
| -infinity
|
|
|
|
| Sat May 10 23:59:12 1947 PST
|
1997-04-27 04:58:38 +02:00
|
|
|
(4 rows)
|
1997-04-05 13:06:04 +02:00
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS four, * FROM ABSTIME_TBL
|
1997-04-27 04:58:38 +02:00
|
|
|
WHERE ABSTIME_TBL.f1 <?>
|
2000-01-05 07:06:23 +01:00
|
|
|
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
|
2001-09-28 10:00:11 +02:00
|
|
|
| Wed Dec 31 16:00:00 1969 PST
|
2000-01-05 07:06:23 +01:00
|
|
|
(3 rows)
|
1997-04-05 13:06:04 +02:00
|
|
|
|
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
|
2001-09-28 10:00:11 +02:00
|
|
|
WHERE isfinite(f1)
|
2000-09-14 17:55:07 +02:00
|
|
|
ORDER BY abstime;
|
|
|
|
four | abstime | year | month | day | hour | minute | second
|
|
|
|
------+------------------------------+------+-------+-----+------+--------+--------
|
|
|
|
| Sat May 10 23:59:12 1947 PST | 1947 | 5 | 10 | 23 | 59 | 12
|
2001-09-28 10:00:11 +02:00
|
|
|
| Wed Dec 31 16:00:00 1969 PST | 1969 | 12 | 31 | 16 | 0 | 0
|
2000-09-14 17:55:07 +02:00
|
|
|
| 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)
|
1997-04-05 13:06:04 +02:00
|
|
|
|