Commit 8997675c authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

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.
parent 41f1f5b7
This source diff could not be displayed because it is too large. You can view the blob instead.
-- --
-- TIMESPAN -- INTERVAL
-- --
CREATE TABLE TIMESPAN_TBL (f1 timespan); CREATE TABLE INTERVAL_TBL (f1 interval);
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 1 minute'); INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 1 minute');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 5 hour'); INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 5 hour');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 10 day'); INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 10 day');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 34 year'); INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 34 year');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 3 months'); INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 3 months');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 14 seconds ago'); INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 14 seconds ago');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('1 day 2 hours 3 minutes 4 seconds'); INSERT INTO INTERVAL_TBL (f1) VALUES ('1 day 2 hours 3 minutes 4 seconds');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('6 years'); INSERT INTO INTERVAL_TBL (f1) VALUES ('6 years');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('5 months'); INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('5 months 12 hours'); INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months 12 hours');
-- badly formatted timespan -- badly formatted interval
INSERT INTO TIMESPAN_TBL (f1) VALUES ('badly formatted timespan'); INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted interval');
ERROR: Bad timespan external representation 'badly formatted timespan' ERROR: Bad interval external representation 'badly formatted interval'
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 30 eons ago'); INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
ERROR: Bad timespan external representation '@ 30 eons ago' ERROR: Bad interval external representation '@ 30 eons ago'
-- test timespan operators -- test interval operators
SELECT '' AS ten, TIMESPAN_TBL.*; SELECT '' AS ten, INTERVAL_TBL.*;
ten | f1 ten | f1
-----+------------------------------- -----+-------------------------------
| @ 1 min | @ 1 min
...@@ -33,8 +33,8 @@ SELECT '' AS ten, TIMESPAN_TBL.*; ...@@ -33,8 +33,8 @@ SELECT '' AS ten, TIMESPAN_TBL.*;
| @ 5 mons 12 hours | @ 5 mons 12 hours
(10 rows) (10 rows)
SELECT '' AS nine, TIMESPAN_TBL.* SELECT '' AS nine, INTERVAL_TBL.*
WHERE TIMESPAN_TBL.f1 <> timespan '@ 10 days'; WHERE INTERVAL_TBL.f1 <> interval '@ 10 days';
nine | f1 nine | f1
------+------------------------------- ------+-------------------------------
| @ 1 min | @ 1 min
...@@ -48,8 +48,8 @@ SELECT '' AS nine, TIMESPAN_TBL.* ...@@ -48,8 +48,8 @@ SELECT '' AS nine, TIMESPAN_TBL.*
| @ 5 mons 12 hours | @ 5 mons 12 hours
(9 rows) (9 rows)
SELECT '' AS three, TIMESPAN_TBL.* SELECT '' AS three, INTERVAL_TBL.*
WHERE TIMESPAN_TBL.f1 <= timespan '@ 5 hours'; WHERE INTERVAL_TBL.f1 <= interval '@ 5 hours';
three | f1 three | f1
-------+--------------- -------+---------------
| @ 1 min | @ 1 min
...@@ -57,8 +57,8 @@ SELECT '' AS three, TIMESPAN_TBL.* ...@@ -57,8 +57,8 @@ SELECT '' AS three, TIMESPAN_TBL.*
| @ 14 secs ago | @ 14 secs ago
(3 rows) (3 rows)
SELECT '' AS three, TIMESPAN_TBL.* SELECT '' AS three, INTERVAL_TBL.*
WHERE TIMESPAN_TBL.f1 < timespan '@ 1 day'; WHERE INTERVAL_TBL.f1 < interval '@ 1 day';
three | f1 three | f1
-------+--------------- -------+---------------
| @ 1 min | @ 1 min
...@@ -66,15 +66,15 @@ SELECT '' AS three, TIMESPAN_TBL.* ...@@ -66,15 +66,15 @@ SELECT '' AS three, TIMESPAN_TBL.*
| @ 14 secs ago | @ 14 secs ago
(3 rows) (3 rows)
SELECT '' AS one, TIMESPAN_TBL.* SELECT '' AS one, INTERVAL_TBL.*
WHERE TIMESPAN_TBL.f1 = timespan '@ 34 years'; WHERE INTERVAL_TBL.f1 = interval '@ 34 years';
one | f1 one | f1
-----+------------ -----+------------
| @ 34 years | @ 34 years
(1 row) (1 row)
SELECT '' AS five, TIMESPAN_TBL.* SELECT '' AS five, INTERVAL_TBL.*
WHERE TIMESPAN_TBL.f1 >= timespan '@ 1 month'; WHERE INTERVAL_TBL.f1 >= interval '@ 1 month';
five | f1 five | f1
------+------------------- ------+-------------------
| @ 34 years | @ 34 years
...@@ -84,8 +84,8 @@ SELECT '' AS five, TIMESPAN_TBL.* ...@@ -84,8 +84,8 @@ SELECT '' AS five, TIMESPAN_TBL.*
| @ 5 mons 12 hours | @ 5 mons 12 hours
(5 rows) (5 rows)
SELECT '' AS nine, TIMESPAN_TBL.* SELECT '' AS nine, INTERVAL_TBL.*
WHERE TIMESPAN_TBL.f1 > timespan '@ 3 seconds ago'; WHERE INTERVAL_TBL.f1 > interval '@ 3 seconds ago';
nine | f1 nine | f1
------+------------------------------- ------+-------------------------------
| @ 1 min | @ 1 min
...@@ -100,7 +100,7 @@ SELECT '' AS nine, TIMESPAN_TBL.* ...@@ -100,7 +100,7 @@ SELECT '' AS nine, TIMESPAN_TBL.*
(9 rows) (9 rows)
SELECT '' AS fortyfive, r1.*, r2.* SELECT '' AS fortyfive, r1.*, r2.*
FROM TIMESPAN_TBL r1, TIMESPAN_TBL r2 FROM INTERVAL_TBL r1, INTERVAL_TBL r2
WHERE r1.f1 > r2.f1 WHERE r1.f1 > r2.f1
ORDER BY r1.f1, r2.f1; ORDER BY r1.f1, r2.f1;
fortyfive | f1 | f1 fortyfive | f1 | f1
......
...@@ -4,174 +4,178 @@ ...@@ -4,174 +4,178 @@
-- Shorthand values -- Shorthand values
-- Not directly usable for regression testing since these are not constants. -- Not directly usable for regression testing since these are not constants.
-- So, just try to test parser and hope for the best - tgl 97/04/26 -- So, just try to test parser and hope for the best - tgl 97/04/26
SELECT (datetime 'today' = (datetime 'yesterday' + timespan '1 day')) as "True"; SELECT (timestamp 'today' = (timestamp 'yesterday' + interval '1 day')) as "True";
True True
------ ------
t t
(1 row) (1 row)
SELECT (datetime 'today' = (datetime 'tomorrow' - timespan '1 day')) as "True"; SELECT (timestamp 'today' = (timestamp 'tomorrow' - interval '1 day')) as "True";
True True
------ ------
t t
(1 row) (1 row)
SELECT (datetime 'tomorrow' = (datetime 'yesterday' + timespan '2 days')) as "True"; SELECT (timestamp 'tomorrow' = (timestamp 'yesterday' + interval '2 days')) as "True";
True True
------ ------
t t
(1 row) (1 row)
SELECT (datetime 'current' = 'now') as "True"; SELECT (timestamp 'current' = 'now') as "True";
True True
------ ------
t t
(1 row) (1 row)
SELECT (datetime 'now' - 'current') AS "ZeroSecs"; SELECT (timestamp 'now' - 'current') AS "ZeroSecs";
ZeroSecs ZeroSecs
---------- ----------
@ 0 @ 0
(1 row) (1 row)
SET DateStyle = 'Postgres,noneuropean'; SET DateStyle = 'Postgres,noneuropean';
SELECT datetime('1994-01-01', '11:00') AS "Jan_01_1994_11am"; SELECT timestamp('1994-01-01', '11:00') AS "Jan_01_1994_11am";
Jan_01_1994_11am Jan_01_1994_11am
------------------------------ ------------------------------
Sat Jan 01 11:00:00 1994 PST Sat Jan 01 11:00:00 1994 PST
(1 row) (1 row)
CREATE TABLE DATETIME_TBL( d1 datetime); CREATE TABLE TIMESTAMP_TBL ( d1 timestamp);
INSERT INTO DATETIME_TBL VALUES ('current'); INSERT INTO TIMESTAMP_TBL VALUES ('current');
INSERT INTO DATETIME_TBL VALUES ('today'); INSERT INTO TIMESTAMP_TBL VALUES ('today');
INSERT INTO DATETIME_TBL VALUES ('yesterday'); INSERT INTO TIMESTAMP_TBL VALUES ('yesterday');
INSERT INTO DATETIME_TBL VALUES ('tomorrow'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow');
INSERT INTO DATETIME_TBL VALUES ('tomorrow EST'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow EST');
INSERT INTO DATETIME_TBL VALUES ('tomorrow zulu'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow zulu');
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'today'; SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'today';
one one
----- -----
1 1
(1 row) (1 row)
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'tomorrow'; SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'tomorrow';
one one
----- -----
1 1
(1 row) (1 row)
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'yesterday'; SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'yesterday';
one one
----- -----
1 1
(1 row) (1 row)
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'today' + timespan '1 day'; SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'today' + interval '1 day';
one one
----- -----
1 1
(1 row) (1 row)
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'today' - timespan '1 day'; SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'today' - interval '1 day';
one one
----- -----
1 1
(1 row) (1 row)
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'now'; SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'now';
one one
----- -----
1 1
(1 row) (1 row)
DELETE FROM DATETIME_TBL; DELETE FROM TIMESTAMP_TBL;
-- verify uniform transaction time within transaction block -- verify uniform transaction time within transaction block
INSERT INTO DATETIME_TBL VALUES ('current'); INSERT INTO TIMESTAMP_TBL VALUES ('current');
BEGIN; BEGIN;
INSERT INTO DATETIME_TBL VALUES ('now'); INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT count(*) AS two FROM DATETIME_TBL WHERE d1 = datetime 'now'; SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 = timestamp 'now';
two two
----- -----
2 2
(1 row) (1 row)
END; END;
DELETE FROM DATETIME_TBL; DELETE FROM TIMESTAMP_TBL;
-- Special values -- Special values
INSERT INTO DATETIME_TBL VALUES ('invalid'); INSERT INTO TIMESTAMP_TBL VALUES ('invalid');
INSERT INTO DATETIME_TBL VALUES ('-infinity'); INSERT INTO TIMESTAMP_TBL VALUES ('-infinity');
INSERT INTO DATETIME_TBL VALUES ('infinity'); INSERT INTO TIMESTAMP_TBL VALUES ('infinity');
INSERT INTO DATETIME_TBL VALUES ('epoch'); INSERT INTO TIMESTAMP_TBL VALUES ('epoch');
-- Postgres v6.0 standard output format -- Postgres v6.0 standard output format
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
INSERT INTO DATETIME_TBL VALUES ('Invalid Abstime'); INSERT INTO TIMESTAMP_TBL VALUES ('Invalid Abstime');
INSERT INTO DATETIME_TBL VALUES ('Undefined Abstime'); INSERT INTO TIMESTAMP_TBL VALUES ('Undefined Abstime');
-- Variations on Postgres v6.1 standard output format -- Variations on Postgres v6.1 standard output format
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01.000001 1997 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.000001 1997 PST');
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01.999999 1997 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.999999 1997 PST');
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01.4 1997 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.4 1997 PST');
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01.5 1997 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.5 1997 PST');
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01.6 1997 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.6 1997 PST');
-- ISO 8601 format -- ISO 8601 format
INSERT INTO DATETIME_TBL VALUES ('1997-01-02'); INSERT INTO TIMESTAMP_TBL VALUES ('1997-01-02');
INSERT INTO DATETIME_TBL VALUES ('1997-01-02 03:04:05'); INSERT INTO TIMESTAMP_TBL VALUES ('1997-01-02 03:04:05');
INSERT INTO DATETIME_TBL VALUES ('1997-02-10 17:32:01-08'); INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01-08');
INSERT INTO DATETIME_TBL VALUES ('1997-02-10 17:32:01-0800'); INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01-0800');
INSERT INTO DATETIME_TBL VALUES ('1997-02-10 17:32:01 -08:00'); INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01 -08:00');
INSERT INTO DATETIME_TBL VALUES ('19970210 173201 -0800'); INSERT INTO TIMESTAMP_TBL VALUES ('19970210 173201 -0800');
INSERT INTO DATETIME_TBL VALUES ('1997-06-10 17:32:01 -07:00'); INSERT INTO TIMESTAMP_TBL VALUES ('1997-06-10 17:32:01 -07:00');
-- POSIX format
INSERT INTO TIMESTAMP_TBL VALUES ('2000-02-15 23:14:30 GMT+8');
INSERT INTO TIMESTAMP_TBL VALUES ('2000-02-15 23:14:30 EST+3');
ERROR: Bad timestamp external representation '2000-02-15 23:14:30 EST+3'
-- Variations for acceptable input formats -- Variations for acceptable input formats
INSERT INTO DATETIME_TBL VALUES ('Feb 10 17:32:01 1997 -0800'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997 -0800');
INSERT INTO DATETIME_TBL VALUES ('Feb 10 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 10 5:32PM 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 5:32PM 1997');
INSERT INTO DATETIME_TBL VALUES ('1997/02/10 17:32:01-0800'); INSERT INTO TIMESTAMP_TBL VALUES ('1997/02/10 17:32:01-0800');
INSERT INTO DATETIME_TBL VALUES ('1997-02-10 17:32:01 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01 PST');
INSERT INTO DATETIME_TBL VALUES ('Feb-10-1997 17:32:01 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb-10-1997 17:32:01 PST');
INSERT INTO DATETIME_TBL VALUES ('02-10-1997 17:32:01 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('02-10-1997 17:32:01 PST');
INSERT INTO DATETIME_TBL VALUES ('19970210 173201 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('19970210 173201 PST');
INSERT INTO DATETIME_TBL VALUES ('97FEB10 5:32:01PM UTC'); INSERT INTO TIMESTAMP_TBL VALUES ('97FEB10 5:32:01PM UTC');
INSERT INTO DATETIME_TBL VALUES ('97/02/10 17:32:01 UTC'); INSERT INTO TIMESTAMP_TBL VALUES ('97/02/10 17:32:01 UTC');
INSERT INTO DATETIME_TBL VALUES ('97.041 17:32:01 UTC'); INSERT INTO TIMESTAMP_TBL VALUES ('97.041 17:32:01 UTC');
-- Check date conversion and date arithmetic -- Check date conversion and date arithmetic
INSERT INTO DATETIME_TBL VALUES ('1997-06-10 18:32:01 PDT'); INSERT INTO TIMESTAMP_TBL VALUES ('1997-06-10 18:32:01 PDT');
INSERT INTO DATETIME_TBL VALUES ('Feb 10 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 11 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 11 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 12 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 12 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 13 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 13 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 14 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 14 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 15 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 15 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 0097 BC'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 0097 BC');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 0097'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 0097');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 0597'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 0597');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1097'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1097');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1697'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1697');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1797'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1797');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1897'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1897');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 2097'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 2097');
INSERT INTO DATETIME_TBL VALUES ('Feb 28 17:32:01 1996'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 28 17:32:01 1996');
INSERT INTO DATETIME_TBL VALUES ('Feb 29 17:32:01 1996'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1996');
INSERT INTO DATETIME_TBL VALUES ('Mar 01 17:32:01 1996'); INSERT INTO TIMESTAMP_TBL VALUES ('Mar 01 17:32:01 1996');
INSERT INTO DATETIME_TBL VALUES ('Dec 30 17:32:01 1996'); INSERT INTO TIMESTAMP_TBL VALUES ('Dec 30 17:32:01 1996');
INSERT INTO DATETIME_TBL VALUES ('Dec 31 17:32:01 1996'); INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1996');
INSERT INTO DATETIME_TBL VALUES ('Jan 01 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 28 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 28 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 29 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1997');
ERROR: Bad datetime external representation 'Feb 29 17:32:01 1997' ERROR: Bad timestamp external representation 'Feb 29 17:32:01 1997'
INSERT INTO DATETIME_TBL VALUES ('Mar 01 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Mar 01 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Dec 30 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Dec 30 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Dec 31 17:32:01 1997'); INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Dec 31 17:32:01 1999'); INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1999');
INSERT INTO DATETIME_TBL VALUES ('Jan 01 17:32:01 2000'); INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2000');
INSERT INTO DATETIME_TBL VALUES ('Dec 31 17:32:01 2000'); INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 2000');
INSERT INTO DATETIME_TBL VALUES ('Jan 01 17:32:01 2001'); INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2001');
-- Currently unsupported syntax and ranges -- Currently unsupported syntax and ranges
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 -0097'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 -0097');
ERROR: Bad datetime external representation 'Feb 16 17:32:01 -0097' ERROR: Bad timestamp external representation 'Feb 16 17:32:01 -0097'
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 5097 BC'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 5097 BC');
ERROR: Datetime out of range 'Feb 16 17:32:01 5097 BC' ERROR: Timestamp out of range 'Feb 16 17:32:01 5097 BC'
SELECT '' AS sixtythree, d1 FROM DATETIME_TBL; SELECT '' AS sixtythree, d1 FROM TIMESTAMP_TBL;
sixtythree | d1 sixtythree | d1
------------+--------------------------------- ------------+---------------------------------
| invalid | invalid
...@@ -193,6 +197,7 @@ SELECT '' AS sixtythree, d1 FROM DATETIME_TBL; ...@@ -193,6 +197,7 @@ SELECT '' AS sixtythree, d1 FROM DATETIME_TBL;
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Tue Jun 10 17:32:01 1997 PDT | Tue Jun 10 17:32:01 1997 PDT
| Tue Feb 15 23:14:30 2000 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:00 1997 PST | Mon Feb 10 17:32:00 1997 PST
...@@ -235,11 +240,11 @@ SELECT '' AS sixtythree, d1 FROM DATETIME_TBL; ...@@ -235,11 +240,11 @@ SELECT '' AS sixtythree, d1 FROM DATETIME_TBL;
| Sat Jan 01 17:32:01 2000 PST | Sat Jan 01 17:32:01 2000 PST
| Sun Dec 31 17:32:01 2000 PST | Sun Dec 31 17:32:01 2000 PST
| Mon Jan 01 17:32:01 2001 PST | Mon Jan 01 17:32:01 2001 PST
(61 rows) (62 rows)
-- Demonstrate functions and operators -- Demonstrate functions and operators
SELECT '' AS fortythree, d1 FROM DATETIME_TBL SELECT '' AS fortythree, d1 FROM TIMESTAMP_TBL
WHERE d1 > datetime '1997-01-02' and d1 != datetime 'current'; WHERE d1 > timestamp '1997-01-02' and d1 != timestamp 'current';
fortythree | d1 fortythree | d1
------------+--------------------------------- ------------+---------------------------------
| infinity | infinity
...@@ -255,6 +260,7 @@ SELECT '' AS fortythree, d1 FROM DATETIME_TBL ...@@ -255,6 +260,7 @@ SELECT '' AS fortythree, d1 FROM DATETIME_TBL
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Tue Jun 10 17:32:01 1997 PDT | Tue Jun 10 17:32:01 1997 PDT
| Tue Feb 15 23:14:30 2000 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:00 1997 PST | Mon Feb 10 17:32:00 1997 PST
...@@ -284,10 +290,10 @@ SELECT '' AS fortythree, d1 FROM DATETIME_TBL ...@@ -284,10 +290,10 @@ SELECT '' AS fortythree, d1 FROM DATETIME_TBL
| Sat Jan 01 17:32:01 2000 PST | Sat Jan 01 17:32:01 2000 PST
| Sun Dec 31 17:32:01 2000 PST | Sun Dec 31 17:32:01 2000 PST
| Mon Jan 01 17:32:01 2001 PST | Mon Jan 01 17:32:01 2001 PST
(42 rows) (43 rows)
SELECT '' AS fifteen, d1 FROM DATETIME_TBL SELECT '' AS fifteen, d1 FROM TIMESTAMP_TBL
WHERE d1 < datetime '1997-01-02' and d1 != datetime 'current'; WHERE d1 < timestamp '1997-01-02' and d1 != timestamp 'current';
fifteen | d1 fifteen | d1
---------+------------------------------ ---------+------------------------------
| -infinity | -infinity
...@@ -307,15 +313,15 @@ SELECT '' AS fifteen, d1 FROM DATETIME_TBL ...@@ -307,15 +313,15 @@ SELECT '' AS fifteen, d1 FROM DATETIME_TBL
| Wed Jan 01 17:32:01 1997 PST | Wed Jan 01 17:32:01 1997 PST
(15 rows) (15 rows)
SELECT '' AS one, d1 FROM DATETIME_TBL SELECT '' AS one, d1 FROM TIMESTAMP_TBL
WHERE d1 = datetime '1997-01-02' and d1 != datetime 'current'; WHERE d1 = timestamp '1997-01-02' and d1 != timestamp 'current';
one | d1 one | d1
-----+------------------------------ -----+------------------------------
| Thu Jan 02 00:00:00 1997 PST | Thu Jan 02 00:00:00 1997 PST
(1 row) (1 row)
SELECT '' AS fiftyeight, d1 FROM DATETIME_TBL SELECT '' AS fiftyeight, d1 FROM TIMESTAMP_TBL
WHERE d1 != datetime '1997-01-02' and d1 != datetime 'current'; WHERE d1 != timestamp '1997-01-02' and d1 != timestamp 'current';
fiftyeight | d1 fiftyeight | d1
------------+--------------------------------- ------------+---------------------------------
| -infinity | -infinity
...@@ -333,6 +339,7 @@ SELECT '' AS fiftyeight, d1 FROM DATETIME_TBL ...@@ -333,6 +339,7 @@ SELECT '' AS fiftyeight, d1 FROM DATETIME_TBL
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Tue Jun 10 17:32:01 1997 PDT | Tue Jun 10 17:32:01 1997 PDT
| Tue Feb 15 23:14:30 2000 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:00 1997 PST | Mon Feb 10 17:32:00 1997 PST
...@@ -375,10 +382,10 @@ SELECT '' AS fiftyeight, d1 FROM DATETIME_TBL ...@@ -375,10 +382,10 @@ SELECT '' AS fiftyeight, d1 FROM DATETIME_TBL
| Sat Jan 01 17:32:01 2000 PST | Sat Jan 01 17:32:01 2000 PST
| Sun Dec 31 17:32:01 2000 PST | Sun Dec 31 17:32:01 2000 PST
| Mon Jan 01 17:32:01 2001 PST | Mon Jan 01 17:32:01 2001 PST
(57 rows) (58 rows)
SELECT '' AS sixteen, d1 FROM DATETIME_TBL SELECT '' AS sixteen, d1 FROM TIMESTAMP_TBL
WHERE d1 <= datetime '1997-01-02' and d1 != datetime 'current'; WHERE d1 <= timestamp '1997-01-02' and d1 != timestamp 'current';
sixteen | d1 sixteen | d1
---------+------------------------------ ---------+------------------------------
| -infinity | -infinity
...@@ -399,8 +406,8 @@ SELECT '' AS sixteen, d1 FROM DATETIME_TBL ...@@ -399,8 +406,8 @@ SELECT '' AS sixteen, d1 FROM DATETIME_TBL
| Wed Jan 01 17:32:01 1997 PST | Wed Jan 01 17:32:01 1997 PST
(16 rows) (16 rows)
SELECT '' AS fortyfour, d1 FROM DATETIME_TBL SELECT '' AS fortyfour, d1 FROM TIMESTAMP_TBL
WHERE d1 >= datetime '1997-01-02' and d1 != datetime 'current'; WHERE d1 >= timestamp '1997-01-02' and d1 != timestamp 'current';
fortyfour | d1 fortyfour | d1
-----------+--------------------------------- -----------+---------------------------------
| infinity | infinity
...@@ -417,6 +424,7 @@ SELECT '' AS fortyfour, d1 FROM DATETIME_TBL ...@@ -417,6 +424,7 @@ SELECT '' AS fortyfour, d1 FROM DATETIME_TBL
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Tue Jun 10 17:32:01 1997 PDT | Tue Jun 10 17:32:01 1997 PDT
| Tue Feb 15 23:14:30 2000 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:01 1997 PST | Mon Feb 10 17:32:01 1997 PST
| Mon Feb 10 17:32:00 1997 PST | Mon Feb 10 17:32:00 1997 PST
...@@ -446,9 +454,9 @@ SELECT '' AS fortyfour, d1 FROM DATETIME_TBL ...@@ -446,9 +454,9 @@ SELECT '' AS fortyfour, d1 FROM DATETIME_TBL
| Sat Jan 01 17:32:01 2000 PST | Sat Jan 01 17:32:01 2000 PST
| Sun Dec 31 17:32:01 2000 PST | Sun Dec 31 17:32:01 2000 PST
| Mon Jan 01 17:32:01 2001 PST | Mon Jan 01 17:32:01 2001 PST
(43 rows) (44 rows)
SELECT '' AS sixtythree, d1 + timespan '1 year' AS one_year FROM DATETIME_TBL; SELECT '' AS sixtythree, d1 + interval '1 year' AS one_year FROM TIMESTAMP_TBL;
sixtythree | one_year sixtythree | one_year
------------+--------------------------------- ------------+---------------------------------
| invalid | invalid
...@@ -470,6 +478,7 @@ SELECT '' AS sixtythree, d1 + timespan '1 year' AS one_year FROM DATETIME_TBL; ...@@ -470,6 +478,7 @@ SELECT '' AS sixtythree, d1 + timespan '1 year' AS one_year FROM DATETIME_TBL;
| Tue Feb 10 17:32:01 1998 PST | Tue Feb 10 17:32:01 1998 PST
| Tue Feb 10 17:32:01 1998 PST | Tue Feb 10 17:32:01 1998 PST
| Wed Jun 10 17:32:01 1998 PDT | Wed Jun 10 17:32:01 1998 PDT
| Thu Feb 15 23:14:30 2001 PST
| Tue Feb 10 17:32:01 1998 PST | Tue Feb 10 17:32:01 1998 PST
| Tue Feb 10 17:32:01 1998 PST | Tue Feb 10 17:32:01 1998 PST
| Tue Feb 10 17:32:00 1998 PST | Tue Feb 10 17:32:00 1998 PST
...@@ -512,9 +521,9 @@ SELECT '' AS sixtythree, d1 + timespan '1 year' AS one_year FROM DATETIME_TBL; ...@@ -512,9 +521,9 @@ SELECT '' AS sixtythree, d1 + timespan '1 year' AS one_year FROM DATETIME_TBL;
| Mon Jan 01 17:32:01 2001 PST | Mon Jan 01 17:32:01 2001 PST
| Mon Dec 31 17:32:01 2001 PST | Mon Dec 31 17:32:01 2001 PST
| Tue Jan 01 17:32:01 2002 PST | Tue Jan 01 17:32:01 2002 PST
(61 rows) (62 rows)
SELECT '' AS sixtythree, d1 - timespan '1 year' AS one_year FROM DATETIME_TBL; SELECT '' AS sixtythree, d1 - interval '1 year' AS one_year FROM TIMESTAMP_TBL;
sixtythree | one_year sixtythree | one_year
------------+--------------------------------- ------------+---------------------------------
| invalid | invalid
...@@ -536,6 +545,7 @@ SELECT '' AS sixtythree, d1 - timespan '1 year' AS one_year FROM DATETIME_TBL; ...@@ -536,6 +545,7 @@ SELECT '' AS sixtythree, d1 - timespan '1 year' AS one_year FROM DATETIME_TBL;
| Sat Feb 10 17:32:01 1996 PST | Sat Feb 10 17:32:01 1996 PST
| Sat Feb 10 17:32:01 1996 PST | Sat Feb 10 17:32:01 1996 PST
| Mon Jun 10 17:32:01 1996 PDT | Mon Jun 10 17:32:01 1996 PDT
| Mon Feb 15 23:14:30 1999 PST
| Sat Feb 10 17:32:01 1996 PST | Sat Feb 10 17:32:01 1996 PST
| Sat Feb 10 17:32:01 1996 PST | Sat Feb 10 17:32:01 1996 PST
| Sat Feb 10 17:32:00 1996 PST | Sat Feb 10 17:32:00 1996 PST
...@@ -578,13 +588,13 @@ SELECT '' AS sixtythree, d1 - timespan '1 year' AS one_year FROM DATETIME_TBL; ...@@ -578,13 +588,13 @@ SELECT '' AS sixtythree, d1 - timespan '1 year' AS one_year FROM DATETIME_TBL;
| Fri Jan 01 17:32:01 1999 PST | Fri Jan 01 17:32:01 1999 PST
| Fri Dec 31 17:32:01 1999 PST | Fri Dec 31 17:32:01 1999 PST
| Sat Jan 01 17:32:01 2000 PST | Sat Jan 01 17:32:01 2000 PST
(61 rows) (62 rows)
-- Casting within a BETWEEN qualifier should probably be allowed by the parser. - tgl 97/04/26 -- Casting within a BETWEEN qualifier should probably be allowed by the parser. - tgl 97/04/26
--SELECT '' AS fifty, d1 - datetime '1997-01-02' AS diff --SELECT '' AS fifty, d1 - timestamp '1997-01-02' AS diff
-- FROM DATETIME_TBL WHERE d1 BETWEEN datetime '1902-01-01' AND datetime '2038-01-01'; -- FROM TIMESTAMP_TBL WHERE d1 BETWEEN timestamp '1902-01-01' AND timestamp '2038-01-01';
SELECT '' AS fifty, d1 - datetime '1997-01-02' AS diff SELECT '' AS fifty, d1 - timestamp '1997-01-02' AS diff
FROM DATETIME_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01'; FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
fifty | diff fifty | diff
-------+---------------------------------------- -------+----------------------------------------
| @ 9863 days 8 hours ago | @ 9863 days 8 hours ago
...@@ -601,6 +611,7 @@ SELECT '' AS fifty, d1 - datetime '1997-01-02' AS diff ...@@ -601,6 +611,7 @@ SELECT '' AS fifty, d1 - datetime '1997-01-02' AS diff
| @ 39 days 17 hours 32 mins 1 sec | @ 39 days 17 hours 32 mins 1 sec
| @ 39 days 17 hours 32 mins 1 sec | @ 39 days 17 hours 32 mins 1 sec
| @ 159 days 16 hours 32 mins 1 sec | @ 159 days 16 hours 32 mins 1 sec
| @ 1139 days 23 hours 14 mins 30 secs
| @ 39 days 17 hours 32 mins 1 sec | @ 39 days 17 hours 32 mins 1 sec
| @ 39 days 17 hours 32 mins 1 sec | @ 39 days 17 hours 32 mins 1 sec
| @ 39 days 17 hours 32 mins | @ 39 days 17 hours 32 mins
...@@ -635,12 +646,12 @@ SELECT '' AS fifty, d1 - datetime '1997-01-02' AS diff ...@@ -635,12 +646,12 @@ SELECT '' AS fifty, d1 - datetime '1997-01-02' AS diff
| @ 1094 days 17 hours 32 mins 1 sec | @ 1094 days 17 hours 32 mins 1 sec
| @ 1459 days 17 hours 32 mins 1 sec | @ 1459 days 17 hours 32 mins 1 sec
| @ 1460 days 17 hours 32 mins 1 sec | @ 1460 days 17 hours 32 mins 1 sec
(48 rows) (49 rows)
SELECT '' AS fortynine, date_part( 'year', d1) AS year, date_part( 'month', d1) AS month, SELECT '' AS fortynine, date_part( 'year', d1) AS year, date_part( 'month', d1) AS month,
date_part( 'day', d1) AS day, date_part( 'hour', d1) AS hour, date_part( 'day', d1) AS day, date_part( 'hour', d1) AS hour,
date_part( 'minute', d1) AS minute, date_part( 'second', d1) AS second date_part( 'minute', d1) AS minute, date_part( 'second', d1) AS second
FROM DATETIME_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01'; FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
fortynine | year | month | day | hour | minute | second fortynine | year | month | day | hour | minute | second
-----------+------+-------+-----+------+--------+---------- -----------+------+-------+-----+------+--------+----------
| 1969 | 12 | 31 | 16 | 0 | 0 | 1969 | 12 | 31 | 16 | 0 | 0
...@@ -657,6 +668,7 @@ SELECT '' AS fortynine, date_part( 'year', d1) AS year, date_part( 'month', d1) ...@@ -657,6 +668,7 @@ SELECT '' AS fortynine, date_part( 'year', d1) AS year, date_part( 'month', d1)
| 1997 | 2 | 10 | 17 | 32 | 1 | 1997 | 2 | 10 | 17 | 32 | 1
| 1997 | 2 | 10 | 17 | 32 | 1 | 1997 | 2 | 10 | 17 | 32 | 1
| 1997 | 6 | 10 | 17 | 32 | 1 | 1997 | 6 | 10 | 17 | 32 | 1
| 2000 | 2 | 15 | 23 | 14 | 30
| 1997 | 2 | 10 | 17 | 32 | 1 | 1997 | 2 | 10 | 17 | 32 | 1
| 1997 | 2 | 10 | 17 | 32 | 1 | 1997 | 2 | 10 | 17 | 32 | 1
| 1997 | 2 | 10 | 17 | 32 | 0 | 1997 | 2 | 10 | 17 | 32 | 0
...@@ -691,11 +703,11 @@ SELECT '' AS fortynine, date_part( 'year', d1) AS year, date_part( 'month', d1) ...@@ -691,11 +703,11 @@ SELECT '' AS fortynine, date_part( 'year', d1) AS year, date_part( 'month', d1)
| 2000 | 1 | 1 | 17 | 32 | 1 | 2000 | 1 | 1 | 17 | 32 | 1
| 2000 | 12 | 31 | 17 | 32 | 1 | 2000 | 12 | 31 | 17 | 32 | 1
| 2001 | 1 | 1 | 17 | 32 | 1 | 2001 | 1 | 1 | 17 | 32 | 1
(48 rows) (49 rows)
SELECT '' AS fortynine, date_part( 'quarter', d1) AS quarter, date_part( 'msec', d1) AS msec, SELECT '' AS fortynine, date_part( 'quarter', d1) AS quarter, date_part( 'msec', d1) AS msec,
date_part( 'usec', d1) AS usec date_part( 'usec', d1) AS usec
FROM DATETIME_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01'; FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
fortynine | quarter | msec | usec fortynine | quarter | msec | usec
-----------+---------+----------------------+------------------- -----------+---------+----------------------+-------------------
| 4 | 0 | 0 | 4 | 0 | 0
...@@ -723,6 +735,7 @@ SELECT '' AS fortynine, date_part( 'quarter', d1) AS quarter, date_part( 'msec', ...@@ -723,6 +735,7 @@ SELECT '' AS fortynine, date_part( 'quarter', d1) AS quarter, date_part( 'msec',
| 1 | 0 | 0 | 1 | 0 | 0
| 1 | 0 | 0 | 1 | 0 | 0
| 1 | 0 | 0 | 1 | 0 | 0
| 1 | 0 | 0
| 2 | 0 | 0 | 2 | 0 | 0
| 1 | 0 | 0 | 1 | 0 | 0
| 1 | 0 | 0 | 1 | 0 | 0
...@@ -746,5 +759,5 @@ SELECT '' AS fortynine, date_part( 'quarter', d1) AS quarter, date_part( 'msec', ...@@ -746,5 +759,5 @@ SELECT '' AS fortynine, date_part( 'quarter', d1) AS quarter, date_part( 'msec',
| 1 | 0 | 0 | 1 | 0 | 0
| 4 | 0 | 0 | 4 | 0 | 0
| 1 | 0 | 0 | 1 | 0 | 0
(48 rows) (49 rows)
...@@ -557,7 +557,6 @@ SELECT user_relns() AS user_relns ...@@ -557,7 +557,6 @@ SELECT user_relns() AS user_relns
city city
copy_tbl copy_tbl
d_star d_star
datetime_tbl
default_seq default_seq
default_tbl default_tbl
defaultexpr_tbl defaultexpr_tbl
...@@ -582,6 +581,7 @@ SELECT user_relns() AS user_relns ...@@ -582,6 +581,7 @@ SELECT user_relns() AS user_relns
int2_tbl int2_tbl
int4_tbl int4_tbl
int8_tbl int8_tbl
interval_tbl
iportaltest iportaltest
join3_tbl join3_tbl
join4_tbl join4_tbl
...@@ -616,7 +616,7 @@ SELECT user_relns() AS user_relns ...@@ -616,7 +616,7 @@ SELECT user_relns() AS user_relns
tenk1 tenk1
tenk2 tenk2
text_tbl text_tbl
timespan_tbl timestamp_tbl
tinterval_tbl tinterval_tbl
toyemp toyemp
varchar_tbl varchar_tbl
......
--
-- DATETIME
--
-- Shorthand values
-- Not directly usable for regression testing since these are not constants.
-- So, just try to test parser and hope for the best - tgl 97/04/26
SELECT (datetime 'today' = (datetime 'yesterday' + timespan '1 day')) as "True";
SELECT (datetime 'today' = (datetime 'tomorrow' - timespan '1 day')) as "True";
SELECT (datetime 'tomorrow' = (datetime 'yesterday' + timespan '2 days')) as "True";
SELECT (datetime 'current' = 'now') as "True";
SELECT (datetime 'now' - 'current') AS "ZeroSecs";
SET DateStyle = 'Postgres,noneuropean';
SELECT datetime('1994-01-01', '11:00') AS "Jan_01_1994_11am";
CREATE TABLE DATETIME_TBL( d1 datetime);
INSERT INTO DATETIME_TBL VALUES ('current');
INSERT INTO DATETIME_TBL VALUES ('today');
INSERT INTO DATETIME_TBL VALUES ('yesterday');
INSERT INTO DATETIME_TBL VALUES ('tomorrow');
INSERT INTO DATETIME_TBL VALUES ('tomorrow EST');
INSERT INTO DATETIME_TBL VALUES ('tomorrow zulu');
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'today';
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'tomorrow';
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'yesterday';
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'today' + timespan '1 day';
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'today' - timespan '1 day';
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = datetime 'now';
DELETE FROM DATETIME_TBL;
-- verify uniform transaction time within transaction block
INSERT INTO DATETIME_TBL VALUES ('current');
BEGIN;
INSERT INTO DATETIME_TBL VALUES ('now');
SELECT count(*) AS two FROM DATETIME_TBL WHERE d1 = datetime 'now';
END;
DELETE FROM DATETIME_TBL;
-- Special values
INSERT INTO DATETIME_TBL VALUES ('invalid');
INSERT INTO DATETIME_TBL VALUES ('-infinity');
INSERT INTO DATETIME_TBL VALUES ('infinity');
INSERT INTO DATETIME_TBL VALUES ('epoch');
-- Postgres v6.0 standard output format
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
INSERT INTO DATETIME_TBL VALUES ('Invalid Abstime');
INSERT INTO DATETIME_TBL VALUES ('Undefined Abstime');
-- Variations on Postgres v6.1 standard output format
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01.000001 1997 PST');
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01.999999 1997 PST');
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01.4 1997 PST');
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01.5 1997 PST');
INSERT INTO DATETIME_TBL VALUES ('Mon Feb 10 17:32:01.6 1997 PST');
-- ISO 8601 format
INSERT INTO DATETIME_TBL VALUES ('1997-01-02');
INSERT INTO DATETIME_TBL VALUES ('1997-01-02 03:04:05');
INSERT INTO DATETIME_TBL VALUES ('1997-02-10 17:32:01-08');
INSERT INTO DATETIME_TBL VALUES ('1997-02-10 17:32:01-0800');
INSERT INTO DATETIME_TBL VALUES ('1997-02-10 17:32:01 -08:00');
INSERT INTO DATETIME_TBL VALUES ('19970210 173201 -0800');
INSERT INTO DATETIME_TBL VALUES ('1997-06-10 17:32:01 -07:00');
-- Variations for acceptable input formats
INSERT INTO DATETIME_TBL VALUES ('Feb 10 17:32:01 1997 -0800');
INSERT INTO DATETIME_TBL VALUES ('Feb 10 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 10 5:32PM 1997');
INSERT INTO DATETIME_TBL VALUES ('1997/02/10 17:32:01-0800');
INSERT INTO DATETIME_TBL VALUES ('1997-02-10 17:32:01 PST');
INSERT INTO DATETIME_TBL VALUES ('Feb-10-1997 17:32:01 PST');
INSERT INTO DATETIME_TBL VALUES ('02-10-1997 17:32:01 PST');
INSERT INTO DATETIME_TBL VALUES ('19970210 173201 PST');
INSERT INTO DATETIME_TBL VALUES ('97FEB10 5:32:01PM UTC');
INSERT INTO DATETIME_TBL VALUES ('97/02/10 17:32:01 UTC');
INSERT INTO DATETIME_TBL VALUES ('97.041 17:32:01 UTC');
-- Check date conversion and date arithmetic
INSERT INTO DATETIME_TBL VALUES ('1997-06-10 18:32:01 PDT');
INSERT INTO DATETIME_TBL VALUES ('Feb 10 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 11 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 12 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 13 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 14 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 15 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 0097 BC');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 0097');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 0597');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1097');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1697');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1797');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1897');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 2097');
INSERT INTO DATETIME_TBL VALUES ('Feb 28 17:32:01 1996');
INSERT INTO DATETIME_TBL VALUES ('Feb 29 17:32:01 1996');
INSERT INTO DATETIME_TBL VALUES ('Mar 01 17:32:01 1996');
INSERT INTO DATETIME_TBL VALUES ('Dec 30 17:32:01 1996');
INSERT INTO DATETIME_TBL VALUES ('Dec 31 17:32:01 1996');
INSERT INTO DATETIME_TBL VALUES ('Jan 01 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 28 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Feb 29 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Mar 01 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Dec 30 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Dec 31 17:32:01 1997');
INSERT INTO DATETIME_TBL VALUES ('Dec 31 17:32:01 1999');
INSERT INTO DATETIME_TBL VALUES ('Jan 01 17:32:01 2000');
INSERT INTO DATETIME_TBL VALUES ('Dec 31 17:32:01 2000');
INSERT INTO DATETIME_TBL VALUES ('Jan 01 17:32:01 2001');
-- Currently unsupported syntax and ranges
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 -0097');
INSERT INTO DATETIME_TBL VALUES ('Feb 16 17:32:01 5097 BC');
SELECT '' AS sixtythree, d1 FROM DATETIME_TBL;
-- Demonstrate functions and operators
SELECT '' AS fortythree, d1 FROM DATETIME_TBL
WHERE d1 > datetime '1997-01-02' and d1 != datetime 'current';
SELECT '' AS fifteen, d1 FROM DATETIME_TBL
WHERE d1 < datetime '1997-01-02' and d1 != datetime 'current';
SELECT '' AS one, d1 FROM DATETIME_TBL
WHERE d1 = datetime '1997-01-02' and d1 != datetime 'current';
SELECT '' AS fiftyeight, d1 FROM DATETIME_TBL
WHERE d1 != datetime '1997-01-02' and d1 != datetime 'current';
SELECT '' AS sixteen, d1 FROM DATETIME_TBL
WHERE d1 <= datetime '1997-01-02' and d1 != datetime 'current';
SELECT '' AS fortyfour, d1 FROM DATETIME_TBL
WHERE d1 >= datetime '1997-01-02' and d1 != datetime 'current';
SELECT '' AS sixtythree, d1 + timespan '1 year' AS one_year FROM DATETIME_TBL;
SELECT '' AS sixtythree, d1 - timespan '1 year' AS one_year FROM DATETIME_TBL;
-- Casting within a BETWEEN qualifier should probably be allowed by the parser. - tgl 97/04/26
--SELECT '' AS fifty, d1 - datetime '1997-01-02' AS diff
-- FROM DATETIME_TBL WHERE d1 BETWEEN datetime '1902-01-01' AND datetime '2038-01-01';
SELECT '' AS fifty, d1 - datetime '1997-01-02' AS diff
FROM DATETIME_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
SELECT '' AS fortynine, date_part( 'year', d1) AS year, date_part( 'month', d1) AS month,
date_part( 'day', d1) AS day, date_part( 'hour', d1) AS hour,
date_part( 'minute', d1) AS minute, date_part( 'second', d1) AS second
FROM DATETIME_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
SELECT '' AS fortynine, date_part( 'quarter', d1) AS quarter, date_part( 'msec', d1) AS msec,
date_part( 'usec', d1) AS usec
FROM DATETIME_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
...@@ -3,52 +3,52 @@ ...@@ -3,52 +3,52 @@
-- --
-- --
-- datetime, timespan arithmetic -- timestamp, interval arithmetic
-- --
SELECT datetime '1996-03-01' - timespan '1 second' AS "Feb 29"; SELECT timestamp '1996-03-01' - interval '1 second' AS "Feb 29";
SELECT datetime '1999-03-01' - timespan '1 second' AS "Feb 28"; SELECT timestamp '1999-03-01' - interval '1 second' AS "Feb 28";
SELECT datetime '2000-03-01' - timespan '1 second' AS "Feb 29"; SELECT timestamp '2000-03-01' - interval '1 second' AS "Feb 29";
SELECT datetime '1999-12-01' + timespan '1 month - 1 second' AS "Dec 31"; SELECT timestamp '1999-12-01' + interval '1 month - 1 second' AS "Dec 31";
CREATE TABLE TEMP_DATETIME (f1 datetime); CREATE TABLE TEMP_TIMESTAMP (f1 timestamp);
-- get some candidate input values -- get some candidate input values
INSERT INTO TEMP_DATETIME (f1) INSERT INTO TEMP_TIMESTAMP (f1)
SELECT d1 FROM DATETIME_TBL SELECT d1 FROM TIMESTAMP_TBL
WHERE d1 BETWEEN '13-jun-1957' AND '1-jan-1997' WHERE d1 BETWEEN '13-jun-1957' AND '1-jan-1997'
OR d1 BETWEEN '1-jan-1999' AND '1-jan-2010'; OR d1 BETWEEN '1-jan-1999' AND '1-jan-2010';
SELECT '' AS ten, f1 AS datetime SELECT '' AS "11", f1 AS timestamp
FROM TEMP_DATETIME FROM TEMP_TIMESTAMP
ORDER BY datetime; ORDER BY timestamp;
SELECT '' AS hundred, d.f1 AS datetime, t.f1 AS timespan, d.f1 + t.f1 AS plus SELECT '' AS "110", d.f1 AS timestamp, t.f1 AS interval, d.f1 + t.f1 AS plus
FROM TEMP_DATETIME d, TIMESPAN_TBL t FROM TEMP_TIMESTAMP d, INTERVAL_TBL t
ORDER BY plus, datetime, timespan; ORDER BY plus, timestamp, interval;
SELECT '' AS hundred, d.f1 AS datetime, t.f1 AS timespan, d.f1 - t.f1 AS minus SELECT '' AS "110", d.f1 AS timestamp, t.f1 AS interval, d.f1 - t.f1 AS minus
FROM TEMP_DATETIME d, TIMESPAN_TBL t FROM TEMP_TIMESTAMP d, INTERVAL_TBL t
WHERE isfinite(d.f1) WHERE isfinite(d.f1)
ORDER BY minus, datetime, timespan; ORDER BY minus, timestamp, interval;
SELECT '' AS ten, d.f1 AS datetime, datetime '1980-01-06 00:00 GMT' AS gpstime_zero, SELECT '' AS "11", d.f1 AS timestamp, timestamp '1980-01-06 00:00 GMT' AS gpstime_zero,
d.f1 - datetime '1980-01-06 00:00 GMT' AS difference d.f1 - timestamp '1980-01-06 00:00 GMT' AS difference
FROM TEMP_DATETIME d FROM TEMP_TIMESTAMP d
ORDER BY difference; ORDER BY difference;
SELECT '' AS hundred, d1.f1 AS datetime1, d2.f1 AS datetime2, d1.f1 - d2.f1 AS difference SELECT '' AS "121", d1.f1 AS timestamp1, d2.f1 AS timestamp2, d1.f1 - d2.f1 AS difference
FROM TEMP_DATETIME d1, TEMP_DATETIME d2 FROM TEMP_TIMESTAMP d1, TEMP_TIMESTAMP d2
ORDER BY datetime1, datetime2, difference; ORDER BY timestamp1, timestamp2, difference;
SELECT '' as fifty, d1 as datetime, SELECT '' as fifty, d1 as timestamp,
date_part('year', d1) AS year, date_part('month', d1) AS month, date_part('year', d1) AS year, date_part('month', d1) AS month,
date_part('day',d1) AS day, date_part('hour', d1) AS hour, date_part('day',d1) AS day, date_part('hour', d1) AS hour,
date_part('minute', d1) AS minute, date_part('second', d1) AS second date_part('minute', d1) AS minute, date_part('second', d1) AS second
FROM DATETIME_TBL FROM TIMESTAMP_TBL
WHERE isfinite(d1) and d1 >= '1-jan-1900 GMT' WHERE isfinite(d1) and d1 >= '1-jan-1900 GMT'
ORDER BY datetime; ORDER BY timestamp;
-- --
-- abstime, reltime arithmetic -- abstime, reltime arithmetic
...@@ -63,52 +63,52 @@ SELECT '' AS four, f1 AS abstime, ...@@ -63,52 +63,52 @@ SELECT '' AS four, f1 AS abstime,
ORDER BY abstime; ORDER BY abstime;
-- --
-- conversions -- Conversions
-- --
SELECT '' AS ten, f1 AS datetime, date( f1) AS date SELECT '' AS "11", f1 AS timestamp, date( f1) AS date
FROM TEMP_DATETIME FROM TEMP_TIMESTAMP
WHERE f1 <> datetime 'current' WHERE f1 <> timestamp 'current'
ORDER BY date; ORDER BY date;
SELECT '' AS ten, f1 AS datetime, abstime( f1) AS abstime SELECT '' AS "11", f1 AS timestamp, abstime( f1) AS abstime
FROM TEMP_DATETIME FROM TEMP_TIMESTAMP
ORDER BY abstime; ORDER BY abstime;
SELECT '' AS five, f1 AS abstime, date( f1) AS date SELECT '' AS four, f1 AS abstime, date( f1) AS date
FROM ABSTIME_TBL FROM ABSTIME_TBL
WHERE isfinite(f1) AND f1 <> abstime 'current' WHERE isfinite(f1) AND f1 <> abstime 'current'
ORDER BY date; ORDER BY date;
SELECT '' AS five, d1 AS datetime, abstime(d1) AS abstime SELECT '' AS five, d1 AS timestamp, abstime(d1) AS abstime
FROM DATETIME_TBL WHERE NOT isfinite(d1); FROM TIMESTAMP_TBL WHERE NOT isfinite(d1);
SELECT '' AS three, f1 as abstime, datetime(f1) AS datetime SELECT '' AS three, f1 as abstime, timestamp(f1) AS timestamp
FROM ABSTIME_TBL WHERE NOT isfinite(f1); FROM ABSTIME_TBL WHERE NOT isfinite(f1);
SELECT '' AS ten, f1 AS timespan, reltime( f1) AS reltime SELECT '' AS ten, f1 AS interval, reltime( f1) AS reltime
FROM TIMESPAN_TBL; FROM INTERVAL_TBL;
SELECT '' AS six, f1 as reltime, timespan( f1) AS timespan SELECT '' AS six, f1 as reltime, interval( f1) AS interval
FROM RELTIME_TBL; FROM RELTIME_TBL;
DROP TABLE TEMP_DATETIME; DROP TABLE TEMP_TIMESTAMP;
-- --
-- formats -- Formats
-- --
SET DateStyle TO 'US,Postgres'; SET DateStyle TO 'US,Postgres';
SHOW DateStyle; SHOW DateStyle;
SELECT '' AS sixty_two, d1 AS us_postgres FROM DATETIME_TBL; SELECT '' AS sixty_two, d1 AS us_postgres FROM TIMESTAMP_TBL;
SELECT '' AS eight, f1 AS us_postgres FROM ABSTIME_TBL; SELECT '' AS eight, f1 AS us_postgres FROM ABSTIME_TBL;
SET DateStyle TO 'US,ISO'; SET DateStyle TO 'US,ISO';
SELECT '' AS sixty_two, d1 AS us_iso FROM DATETIME_TBL; SELECT '' AS sixty_two, d1 AS us_iso FROM TIMESTAMP_TBL;
SELECT '' AS eight, f1 AS us_iso FROM ABSTIME_TBL; SELECT '' AS eight, f1 AS us_iso FROM ABSTIME_TBL;
...@@ -116,7 +116,7 @@ SET DateStyle TO 'US,SQL'; ...@@ -116,7 +116,7 @@ SET DateStyle TO 'US,SQL';
SHOW DateStyle; SHOW DateStyle;
SELECT '' AS sixty_two, d1 AS us_sql FROM DATETIME_TBL; SELECT '' AS sixty_two, d1 AS us_sql FROM TIMESTAMP_TBL;
SELECT '' AS eight, f1 AS us_sql FROM ABSTIME_TBL; SELECT '' AS eight, f1 AS us_sql FROM ABSTIME_TBL;
...@@ -124,11 +124,11 @@ SET DateStyle TO 'European,Postgres'; ...@@ -124,11 +124,11 @@ SET DateStyle TO 'European,Postgres';
SHOW DateStyle; SHOW DateStyle;
INSERT INTO DATETIME_TBL VALUES('13/06/1957'); INSERT INTO TIMESTAMP_TBL VALUES('13/06/1957');
SELECT count(*) as one FROM DATETIME_TBL WHERE d1 = 'Jun 13 1957'; SELECT count(*) as one FROM TIMESTAMP_TBL WHERE d1 = 'Jun 13 1957';
SELECT '' AS sixty_three, d1 AS european_postgres FROM DATETIME_TBL; SELECT '' AS sixty_three, d1 AS european_postgres FROM TIMESTAMP_TBL;
SELECT '' AS eight, f1 AS european_postgres FROM ABSTIME_TBL; SELECT '' AS eight, f1 AS european_postgres FROM ABSTIME_TBL;
...@@ -136,7 +136,7 @@ SET DateStyle TO 'European,ISO'; ...@@ -136,7 +136,7 @@ SET DateStyle TO 'European,ISO';
SHOW DateStyle; SHOW DateStyle;
SELECT '' AS sixty_three, d1 AS european_iso FROM DATETIME_TBL; SELECT '' AS sixty_three, d1 AS european_iso FROM TIMESTAMP_TBL;
SELECT '' AS eight, f1 AS european_iso FROM ABSTIME_TBL; SELECT '' AS eight, f1 AS european_iso FROM ABSTIME_TBL;
...@@ -144,65 +144,7 @@ SET DateStyle TO 'European,SQL'; ...@@ -144,65 +144,7 @@ SET DateStyle TO 'European,SQL';
SHOW DateStyle; SHOW DateStyle;
SELECT '' AS sixty_three, d1 AS european_sql FROM DATETIME_TBL; SELECT '' AS sixty_three, d1 AS european_sql FROM TIMESTAMP_TBL;
SELECT '' AS eight, f1 AS european_sql FROM ABSTIME_TBL;
RESET DateStyle;
SHOW DateStyle;
--
-- formats
--
SET DateStyle TO 'US,Postgres';
SHOW DateStyle;
SELECT '' AS sixty_two, d1 AS us_postgres FROM DATETIME_TBL;
SELECT '' AS eight, f1 AS us_postgres FROM ABSTIME_TBL;
SET DateStyle TO 'US,ISO';
SELECT '' AS sixty_two, d1 AS us_iso FROM DATETIME_TBL;
SELECT '' AS eight, f1 AS us_iso FROM ABSTIME_TBL;
SET DateStyle TO 'US,SQL';
SHOW DateStyle;
SELECT '' AS sixty_two, d1 AS us_sql FROM DATETIME_TBL;
SELECT '' AS eight, f1 AS us_sql FROM ABSTIME_TBL;
SET DateStyle TO 'European,Postgres';
SHOW DateStyle;
INSERT INTO DATETIME_TBL VALUES('13/06/1957');
SELECT count(*) as one FROM DATETIME_TBL WHERE d1 = 'Jun 13 1957';
SELECT '' AS sixty_three, d1 AS european_postgres FROM DATETIME_TBL;
SELECT '' AS eight, f1 AS european_postgres FROM ABSTIME_TBL;
SET DateStyle TO 'European,ISO';
SHOW DateStyle;
SELECT '' AS sixty_three, d1 AS european_iso FROM DATETIME_TBL;
SELECT '' AS eight, f1 AS european_iso FROM ABSTIME_TBL;
SET DateStyle TO 'European,SQL';
SHOW DateStyle;
SELECT '' AS sixty_three, d1 AS european_sql FROM DATETIME_TBL;
SELECT '' AS eight, f1 AS european_sql FROM ABSTIME_TBL; SELECT '' AS eight, f1 AS european_sql FROM ABSTIME_TBL;
......
--
-- INTERVAL
--
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');
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
-- test interval operators
SELECT '' AS ten, INTERVAL_TBL.*;
SELECT '' AS nine, INTERVAL_TBL.*
WHERE INTERVAL_TBL.f1 <> interval '@ 10 days';
SELECT '' AS three, INTERVAL_TBL.*
WHERE INTERVAL_TBL.f1 <= interval '@ 5 hours';
SELECT '' AS three, INTERVAL_TBL.*
WHERE INTERVAL_TBL.f1 < interval '@ 1 day';
SELECT '' AS one, INTERVAL_TBL.*
WHERE INTERVAL_TBL.f1 = interval '@ 34 years';
SELECT '' AS five, INTERVAL_TBL.*
WHERE INTERVAL_TBL.f1 >= interval '@ 1 month';
SELECT '' AS nine, INTERVAL_TBL.*
WHERE INTERVAL_TBL.f1 > interval '@ 3 seconds ago';
SELECT '' AS fortyfive, r1.*, r2.*
FROM INTERVAL_TBL r1, INTERVAL_TBL r2
WHERE r1.f1 > r2.f1
ORDER BY r1.f1, r2.f1;
...@@ -29,8 +29,8 @@ parallel group2 ...@@ -29,8 +29,8 @@ parallel group2
test path test path
test polygon test polygon
test circle test circle
test timespan test interval
test datetime test timestamp
test reltime test reltime
test tinterval test tinterval
test inet test inet
...@@ -42,7 +42,7 @@ endparallel ...@@ -42,7 +42,7 @@ endparallel
test abstime # Depends on the reltime test test abstime # Depends on the reltime test
test geometry # Depends on point, lseg, box, path, polygon and circle test geometry # Depends on point, lseg, box, path, polygon and circle
test horology # Depends on timespan, datetime, reltime and abstime test horology # Depends on interval, timestamp, reltime and abstime
# ---------- # ----------
# These four each depend on the previous one # These four each depend on the previous one
......
...@@ -18,8 +18,8 @@ path ...@@ -18,8 +18,8 @@ path
polygon polygon
circle circle
geometry geometry
timespan interval
datetime timestamp
reltime reltime
abstime abstime
tinterval tinterval
......
--
-- TIMESPAN
--
CREATE TABLE TIMESPAN_TBL (f1 timespan);
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 1 minute');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 5 hour');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 10 day');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 34 year');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 3 months');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 14 seconds ago');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('1 day 2 hours 3 minutes 4 seconds');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('6 years');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('5 months');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('5 months 12 hours');
-- badly formatted timespan
INSERT INTO TIMESPAN_TBL (f1) VALUES ('badly formatted timespan');
INSERT INTO TIMESPAN_TBL (f1) VALUES ('@ 30 eons ago');
-- test timespan operators
SELECT '' AS ten, TIMESPAN_TBL.*;
SELECT '' AS nine, TIMESPAN_TBL.*
WHERE TIMESPAN_TBL.f1 <> timespan '@ 10 days';
SELECT '' AS three, TIMESPAN_TBL.*
WHERE TIMESPAN_TBL.f1 <= timespan '@ 5 hours';
SELECT '' AS three, TIMESPAN_TBL.*
WHERE TIMESPAN_TBL.f1 < timespan '@ 1 day';
SELECT '' AS one, TIMESPAN_TBL.*
WHERE TIMESPAN_TBL.f1 = timespan '@ 34 years';
SELECT '' AS five, TIMESPAN_TBL.*
WHERE TIMESPAN_TBL.f1 >= timespan '@ 1 month';
SELECT '' AS nine, TIMESPAN_TBL.*
WHERE TIMESPAN_TBL.f1 > timespan '@ 3 seconds ago';
SELECT '' AS fortyfive, r1.*, r2.*
FROM TIMESPAN_TBL r1, TIMESPAN_TBL r2
WHERE r1.f1 > r2.f1
ORDER BY r1.f1, r2.f1;
--
-- DATETIME
--
-- Shorthand values
-- Not directly usable for regression testing since these are not constants.
-- So, just try to test parser and hope for the best - tgl 97/04/26
SELECT (timestamp 'today' = (timestamp 'yesterday' + interval '1 day')) as "True";
SELECT (timestamp 'today' = (timestamp 'tomorrow' - interval '1 day')) as "True";
SELECT (timestamp 'tomorrow' = (timestamp 'yesterday' + interval '2 days')) as "True";
SELECT (timestamp 'current' = 'now') as "True";
SELECT (timestamp 'now' - 'current') AS "ZeroSecs";
SET DateStyle = 'Postgres,noneuropean';
SELECT timestamp('1994-01-01', '11:00') AS "Jan_01_1994_11am";
CREATE TABLE TIMESTAMP_TBL ( d1 timestamp);
INSERT INTO TIMESTAMP_TBL VALUES ('current');
INSERT INTO TIMESTAMP_TBL VALUES ('today');
INSERT INTO TIMESTAMP_TBL VALUES ('yesterday');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow EST');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow zulu');
SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'today';
SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'tomorrow';
SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'yesterday';
SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'today' + interval '1 day';
SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'today' - interval '1 day';
SELECT count(*) AS one FROM TIMESTAMP_TBL WHERE d1 = timestamp 'now';
DELETE FROM TIMESTAMP_TBL;
-- verify uniform transaction time within transaction block
INSERT INTO TIMESTAMP_TBL VALUES ('current');
BEGIN;
INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 = timestamp 'now';
END;
DELETE FROM TIMESTAMP_TBL;
-- Special values
INSERT INTO TIMESTAMP_TBL VALUES ('invalid');
INSERT INTO TIMESTAMP_TBL VALUES ('-infinity');
INSERT INTO TIMESTAMP_TBL VALUES ('infinity');
INSERT INTO TIMESTAMP_TBL VALUES ('epoch');
-- Postgres v6.0 standard output format
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Invalid Abstime');
INSERT INTO TIMESTAMP_TBL VALUES ('Undefined Abstime');
-- Variations on Postgres v6.1 standard output format
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.000001 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.999999 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.4 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.5 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.6 1997 PST');
-- ISO 8601 format
INSERT INTO TIMESTAMP_TBL VALUES ('1997-01-02');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-01-02 03:04:05');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01-08');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01-0800');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01 -08:00');
INSERT INTO TIMESTAMP_TBL VALUES ('19970210 173201 -0800');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-06-10 17:32:01 -07:00');
-- POSIX format
INSERT INTO TIMESTAMP_TBL VALUES ('2000-02-15 23:14:30 GMT+8');
INSERT INTO TIMESTAMP_TBL VALUES ('2000-02-15 23:14:30 EST+3');
-- Variations for acceptable input formats
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997 -0800');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 5:32PM 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('1997/02/10 17:32:01-0800');
INSERT INTO TIMESTAMP_TBL VALUES ('1997-02-10 17:32:01 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb-10-1997 17:32:01 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('02-10-1997 17:32:01 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('19970210 173201 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('97FEB10 5:32:01PM UTC');
INSERT INTO TIMESTAMP_TBL VALUES ('97/02/10 17:32:01 UTC');
INSERT INTO TIMESTAMP_TBL VALUES ('97.041 17:32:01 UTC');
-- Check date conversion and date arithmetic
INSERT INTO TIMESTAMP_TBL VALUES ('1997-06-10 18:32:01 PDT');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 11 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 12 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 13 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 14 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 15 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 0097 BC');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 0097');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 0597');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1097');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1697');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1797');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1897');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 2097');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 28 17:32:01 1996');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1996');
INSERT INTO TIMESTAMP_TBL VALUES ('Mar 01 17:32:01 1996');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 30 17:32:01 1996');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1996');
INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 28 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Mar 01 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 30 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1997');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1999');
INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2000');
INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 2000');
INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2001');
-- Currently unsupported syntax and ranges
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 -0097');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 5097 BC');
SELECT '' AS sixtythree, d1 FROM TIMESTAMP_TBL;
-- Demonstrate functions and operators
SELECT '' AS fortythree, d1 FROM TIMESTAMP_TBL
WHERE d1 > timestamp '1997-01-02' and d1 != timestamp 'current';
SELECT '' AS fifteen, d1 FROM TIMESTAMP_TBL
WHERE d1 < timestamp '1997-01-02' and d1 != timestamp 'current';
SELECT '' AS one, d1 FROM TIMESTAMP_TBL
WHERE d1 = timestamp '1997-01-02' and d1 != timestamp 'current';
SELECT '' AS fiftyeight, d1 FROM TIMESTAMP_TBL
WHERE d1 != timestamp '1997-01-02' and d1 != timestamp 'current';
SELECT '' AS sixteen, d1 FROM TIMESTAMP_TBL
WHERE d1 <= timestamp '1997-01-02' and d1 != timestamp 'current';
SELECT '' AS fortyfour, d1 FROM TIMESTAMP_TBL
WHERE d1 >= timestamp '1997-01-02' and d1 != timestamp 'current';
SELECT '' AS sixtythree, d1 + interval '1 year' AS one_year FROM TIMESTAMP_TBL;
SELECT '' AS sixtythree, d1 - interval '1 year' AS one_year FROM TIMESTAMP_TBL;
-- Casting within a BETWEEN qualifier should probably be allowed by the parser. - tgl 97/04/26
--SELECT '' AS fifty, d1 - timestamp '1997-01-02' AS diff
-- FROM TIMESTAMP_TBL WHERE d1 BETWEEN timestamp '1902-01-01' AND timestamp '2038-01-01';
SELECT '' AS fifty, d1 - timestamp '1997-01-02' AS diff
FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
SELECT '' AS fortynine, date_part( 'year', d1) AS year, date_part( 'month', d1) AS month,
date_part( 'day', d1) AS day, date_part( 'hour', d1) AS hour,
date_part( 'minute', d1) AS minute, date_part( 'second', d1) AS second
FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
SELECT '' AS fortynine, date_part( 'quarter', d1) AS quarter, date_part( 'msec', d1) AS msec,
date_part( 'usec', d1) AS usec
FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment