3 -- testing built-in time type abstime
4 -- uses reltime and tinterval
7 -- timezones may vary based not only on location but the operating
8 -- system. the main correctness issue is that the OS may not get
9 -- daylight savings time right for times prior to Unix epoch (jan 1 1970).
11 CREATE TABLE ABSTIME_TBL (f1 abstime);
13 INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'now');
14 INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'now');
15 SELECT count(*) AS two FROM ABSTIME_TBL WHERE f1 = 'now' ;
22 DELETE FROM ABSTIME_TBL;
23 INSERT INTO ABSTIME_TBL (f1) VALUES ('Jan 14, 1973 03:14:21');
24 INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'Mon May 1 00:30:30 1995');
25 INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'epoch');
26 INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'infinity');
27 INSERT INTO ABSTIME_TBL (f1) VALUES (abstime '-infinity');
28 INSERT INTO ABSTIME_TBL (f1) VALUES (abstime 'May 10, 1947 23:59:12');
29 -- what happens if we specify slightly misformatted abstime?
30 INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00');
31 ERROR: date/time field value out of range: "Feb 35, 1946 10:00:00"
32 LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00'...
34 HINT: Perhaps you need a different "datestyle" setting.
35 INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10');
36 ERROR: date/time field value out of range: "Feb 28, 1984 25:08:10"
37 LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10'...
39 -- badly formatted abstimes: these should result in invalid abstimes
40 INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format');
41 ERROR: invalid input syntax for type abstime: "bad date format"
42 LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format');
44 INSERT INTO ABSTIME_TBL (f1) VALUES ('Jun 10, 1843');
45 -- test abstime operators
46 SELECT '' AS eight, * FROM ABSTIME_TBL;
48 -------+------------------------------
49 | Sun Jan 14 03:14:21 1973 PST
50 | Mon May 01 00:30:30 1995 PDT
51 | Wed Dec 31 16:00:00 1969 PST
54 | Sat May 10 23:59:12 1947 PST
58 SELECT '' AS six, * FROM ABSTIME_TBL
59 WHERE ABSTIME_TBL.f1 < abstime 'Jun 30, 2001';
61 -----+------------------------------
62 | Sun Jan 14 03:14:21 1973 PST
63 | Mon May 01 00:30:30 1995 PDT
64 | Wed Dec 31 16:00:00 1969 PST
66 | Sat May 10 23:59:12 1947 PST
69 SELECT '' AS six, * FROM ABSTIME_TBL
70 WHERE ABSTIME_TBL.f1 > abstime '-infinity';
72 -----+------------------------------
73 | Sun Jan 14 03:14:21 1973 PST
74 | Mon May 01 00:30:30 1995 PDT
75 | Wed Dec 31 16:00:00 1969 PST
77 | Sat May 10 23:59:12 1947 PST
81 SELECT '' AS six, * FROM ABSTIME_TBL
82 WHERE abstime 'May 10, 1947 23:59:12' <> ABSTIME_TBL.f1;
84 -----+------------------------------
85 | Sun Jan 14 03:14:21 1973 PST
86 | Mon May 01 00:30:30 1995 PDT
87 | Wed Dec 31 16:00:00 1969 PST
93 SELECT '' AS three, * FROM ABSTIME_TBL
94 WHERE abstime 'epoch' >= ABSTIME_TBL.f1;
96 -------+------------------------------
97 | Wed Dec 31 16:00:00 1969 PST
99 | Sat May 10 23:59:12 1947 PST
102 SELECT '' AS four, * FROM ABSTIME_TBL
103 WHERE ABSTIME_TBL.f1 <= abstime 'Jan 14, 1973 03:14:21';
105 ------+------------------------------
106 | Sun Jan 14 03:14:21 1973 PST
107 | Wed Dec 31 16:00:00 1969 PST
109 | Sat May 10 23:59:12 1947 PST
112 SELECT '' AS four, * FROM ABSTIME_TBL
113 WHERE ABSTIME_TBL.f1 <?>
114 tinterval '["Apr 1 1950 00:00:00" "Dec 30 1999 23:00:00"]';
116 ------+------------------------------
117 | Sun Jan 14 03:14:21 1973 PST
118 | Mon May 01 00:30:30 1995 PDT
119 | Wed Dec 31 16:00:00 1969 PST
122 SELECT '' AS four, f1 AS abstime,
123 date_part('year', f1) AS year, date_part('month', f1) AS month,
124 date_part('day',f1) AS day, date_part('hour', f1) AS hour,
125 date_part('minute', f1) AS minute, date_part('second', f1) AS second
129 four | abstime | year | month | day | hour | minute | second
130 ------+------------------------------+------+-------+-----+------+--------+--------
131 | Sat May 10 23:59:12 1947 PST | 1947 | 5 | 10 | 23 | 59 | 12
132 | Wed Dec 31 16:00:00 1969 PST | 1969 | 12 | 31 | 16 | 0 | 0
133 | Sun Jan 14 03:14:21 1973 PST | 1973 | 1 | 14 | 3 | 14 | 21
134 | Mon May 01 00:30:30 1995 PDT | 1995 | 5 | 1 | 0 | 30 | 30