Commit 0d93504c authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Add regression tests for date, time, and time with time zone types.

Modify date->timestamp conversion to use mktime().
 This should do better than before around Daylight Savings Time
 transitions.
parent 4d745dad
--
-- DATE
--
CREATE TABLE DATE_TBL (f1 date);
INSERT INTO DATE_TBL VALUES ('1957-04-09');
INSERT INTO DATE_TBL VALUES ('1957-06-13');
INSERT INTO DATE_TBL VALUES ('1996-02-28');
INSERT INTO DATE_TBL VALUES ('1996-02-29');
INSERT INTO DATE_TBL VALUES ('1996-03-01');
INSERT INTO DATE_TBL VALUES ('1996-03-02');
INSERT INTO DATE_TBL VALUES ('1997-02-28');
INSERT INTO DATE_TBL VALUES ('1997-02-29');
ERROR: Bad date external representation '1997-02-29'
INSERT INTO DATE_TBL VALUES ('1997-03-01');
INSERT INTO DATE_TBL VALUES ('1997-03-02');
INSERT INTO DATE_TBL VALUES ('2000-04-01');
INSERT INTO DATE_TBL VALUES ('2000-04-02');
INSERT INTO DATE_TBL VALUES ('2000-04-03');
INSERT INTO DATE_TBL VALUES ('2038-04-08');
INSERT INTO DATE_TBL VALUES ('2039-04-09');
INSERT INTO DATE_TBL VALUES ('2040-04-10');
SELECT f1 AS "Fifteen" FROM DATE_TBL;
Fifteen
------------
04-09-1957
06-13-1957
02-28-1996
02-29-1996
03-01-1996
03-02-1996
02-28-1997
03-01-1997
03-02-1997
04-01-2000
04-02-2000
04-03-2000
04-08-2038
04-09-2039
04-10-2040
(15 rows)
SELECT f1 AS "Nine" FROM DATE_TBL WHERE f1 < '2000-01-01';
Nine
------------
04-09-1957
06-13-1957
02-28-1996
02-29-1996
03-01-1996
03-02-1996
02-28-1997
03-01-1997
03-02-1997
(9 rows)
SELECT f1 AS "Three" FROM DATE_TBL
WHERE f1 BETWEEN '2000-01-01' AND '2001-01-01';
Three
------------
04-01-2000
04-02-2000
04-03-2000
(3 rows)
--
-- Simple math
-- Leave most of it for the horology tests
--
SELECT f1 - date '2000-01-01' AS "Days From 2K" FROM DATE_TBL;
Days From 2K
--------------
-15607
-15542
-1403
-1402
-1401
-1400
-1037
-1036
-1035
91
92
93
13977
14343
14710
(15 rows)
SELECT f1 - date 'epoch' AS "Days From Epoch" FROM DATE_TBL;
Days From Epoch
-----------------
-4650
-4585
9554
9555
9556
9557
9920
9921
9922
11048
11049
11050
24934
25300
25667
(15 rows)
SELECT date 'yesterday' - date 'today' AS "One day";
One day
---------
-1
(1 row)
SELECT date 'today' - date 'tomorrow' AS "One day";
One day
---------
-1
(1 row)
SELECT date 'yesterday' - date 'tomorrow' AS "Two days";
Two days
----------
-2
(1 row)
SELECT date 'tomorrow' - date 'today' AS "One day";
One day
---------
1
(1 row)
SELECT date 'today' - date 'yesterday' AS "One day";
One day
---------
1
(1 row)
SELECT date 'tomorrow' - date 'yesterday' AS "Two days";
Two days
----------
2
(1 row)
...@@ -2,6 +2,48 @@ ...@@ -2,6 +2,48 @@
-- HOROLOGY -- HOROLOGY
-- --
-- --
-- date, time arithmetic
--
SELECT date '1981-02-03' + time '04:05:06' AS "Date + Time";
Date + Time
------------------------------
Tue Feb 03 04:05:06 1981 PST
(1 row)
SELECT date '1991-02-03' + time with time zone '04:05:06 PST' AS "Date + Time PST";
Date + Time PST
------------------------------
Sun Feb 03 04:05:06 1991 PST
(1 row)
SELECT date '2001-02-03' + time with time zone '04:05:06 UTC' AS "Date + Time UTC";
Date + Time UTC
------------------------------
Fri Feb 02 20:05:06 2001 PST
(1 row)
SELECT date '1991-02-03' + interval '2 years' AS "Add Two Years";
Add Two Years
------------------------------
Wed Feb 03 00:00:00 1993 PST
(1 row)
SELECT date '2001-12-13' - interval '2 years' AS "Subtract Two Years";
Subtract Two Years
------------------------------
Mon Dec 13 00:00:00 1999 PST
(1 row)
SELECT date '1991-02-03' - time '04:05:06' AS "Subtract Time";
Subtract Time
------------------------------
Sat Feb 02 19:54:54 1991 PST
(1 row)
SELECT date '1991-02-03' - time with time zone '04:05:06 UTC' AS "Subtract Time UTC";
ERROR: Unable to identify an operator '-' for types 'date' and 'timetz'
You will have to retype this query using an explicit cast
--
-- timestamp, interval arithmetic -- timestamp, interval arithmetic
-- --
SELECT timestamp '1996-03-01' - interval '1 second' AS "Feb 29"; SELECT timestamp '1996-03-01' - interval '1 second' AS "Feb 29";
......
--
-- TIME
--
CREATE TABLE TIME_TBL (f1 time, f2 time with time zone);
INSERT INTO TIME_TBL VALUES ('00:00', '00:00 PDT');
INSERT INTO TIME_TBL VALUES ('01:00', '01:00 PDT');
INSERT INTO TIME_TBL VALUES ('02:03', '02:03 PDT');
INSERT INTO TIME_TBL VALUES ('11:59', '11:59 PDT');
INSERT INTO TIME_TBL VALUES ('12:00', '12:00 PDT');
INSERT INTO TIME_TBL VALUES ('12:01', '12:01 PDT');
INSERT INTO TIME_TBL VALUES ('23:59', '23:59 PDT');
INSERT INTO TIME_TBL VALUES ('11:59:59.99 PM', '11:59:59.99 PM PDT');
SELECT f1 AS "Time", f2 AS "Time TZ" FROM TIME_TBL;
Time | Time TZ
----------+-------------
00:00:00 | 00:00:00-07
01:00:00 | 01:00:00-07
02:03:00 | 02:03:00-07
11:59:00 | 11:59:00-07
12:00:00 | 12:00:00-07
12:01:00 | 12:01:00-07
23:59:00 | 23:59:00-07
23:59:59 | 23:59:59-07
(8 rows)
SELECT f1 AS "Three" FROM TIME_TBL WHERE f1 < '05:06:07';
Three
----------
00:00:00
01:00:00
02:03:00
(3 rows)
SELECT f1 AS "Five" FROM TIME_TBL WHERE f1 > '05:06:07';
Five
----------
11:59:00
12:00:00
12:01:00
23:59:00
23:59:59
(5 rows)
SELECT f1 AS "None" FROM TIME_TBL WHERE f1 < '00:00';
None
------
(0 rows)
SELECT f1 AS "Eight" FROM TIME_TBL WHERE f1 >= '00:00';
Eight
----------
00:00:00
01:00:00
02:03:00
11:59:00
12:00:00
12:01:00
23:59:00
23:59:59
(8 rows)
--
-- TIME simple math
--
SELECT f1 + time '00:01' AS "Eight" FROM TIME_TBL;
Eight
--------------------
@ 1 min
@ 1 hour 1 min
@ 2 hours 4 mins
@ 12 hours
@ 12 hours 1 min
@ 12 hours 2 mins
@ 1 day
@ 1 day 59.99 secs
(8 rows)
SELECT f1 + time '01:00' AS "Eight" FROM TIME_TBL;
Eight
----------------------------
@ 1 hour
@ 2 hours
@ 3 hours 3 mins
@ 12 hours 59 mins
@ 13 hours
@ 13 hours 1 min
@ 1 day 59 mins
@ 1 day 59 mins 59.99 secs
(8 rows)
SELECT f1 + time '00:00:01.11' AS "Eight" FROM TIME_TBL;
Eight
------------------------------
@ 1.11 secs
@ 1 hour 1.11 secs
@ 2 hours 3 mins 1.11 secs
@ 11 hours 59 mins 1.11 secs
@ 12 hours 1.11 secs
@ 12 hours 1 min 1.11 secs
@ 23 hours 59 mins 1.11 secs
@ 1 day 1.10 secs
(8 rows)
SELECT f1 + time '00:00:59.99' AS "Eight" FROM TIME_TBL;
Eight
-------------------------------
@ 59.99 secs
@ 1 hour 59.99 secs
@ 2 hours 3 mins 59.99 secs
@ 11 hours 59 mins 59.99 secs
@ 12 hours 59.99 secs
@ 12 hours 1 min 59.99 secs
@ 23 hours 59 mins 59.99 secs
@ 1 day 59.98 secs
(8 rows)
SELECT f1 - '00:01' AS "Eight" FROM TIME_TBL;
Eight
-------------------------------
@ 1 min ago
@ 59 mins
@ 2 hours 2 mins
@ 11 hours 58 mins
@ 11 hours 59 mins
@ 12 hours
@ 23 hours 58 mins
@ 23 hours 58 mins 59.99 secs
(8 rows)
SELECT f1 - '01:00' AS "Eight" FROM TIME_TBL;
Eight
-------------------------------
@ 1 hour ago
@ 0
@ 1 hour 3 mins
@ 10 hours 59 mins
@ 11 hours
@ 11 hours 1 min
@ 22 hours 59 mins
@ 22 hours 59 mins 59.99 secs
(8 rows)
SELECT f1 - '00:00:01.11' AS "Eight" FROM TIME_TBL;
Eight
-------------------------------
@ 1.11 secs ago
@ 59 mins 58.89 secs
@ 2 hours 2 mins 58.89 secs
@ 11 hours 58 mins 58.89 secs
@ 11 hours 59 mins 58.89 secs
@ 12 hours 58.89 secs
@ 23 hours 58 mins 58.89 secs
@ 23 hours 59 mins 58.88 secs
(8 rows)
SELECT f1 - '00:00:59.99' AS "Eight" FROM TIME_TBL;
Eight
------------------------------
@ 59.99 secs ago
@ 59 mins 0.01 secs
@ 2 hours 2 mins 0.01 secs
@ 11 hours 58 mins 0.01 secs
@ 11 hours 59 mins 0.01 secs
@ 12 hours 0.01 secs
@ 23 hours 58 mins 0.01 secs
@ 23 hours 59 mins
(8 rows)
--
-- TIME WITH TIME ZONE simple math
--
/*
-- Not yet implemented
-- Thomas 2000-09-09
SELECT f2 + time '00:01' AS "" FROM TIME_TBL;
SELECT f2 + time '01:00' AS "" FROM TIME_TBL;
SELECT f2 + time '00:00:01.11' AS "" FROM TIME_TBL;
SELECT f2 + '00:00:59.99' AS "" FROM TIME_TBL;
SELECT f2 - '00:01' AS "" FROM TIME_TBL;
SELECT f2 - '01:00' AS "" FROM TIME_TBL;
SELECT f2 - '00:00:01.11' AS "" FROM TIME_TBL;
SELECT f2 - '00:00:59.99' AS "" FROM TIME_TBL;
*/
...@@ -587,6 +587,7 @@ SELECT user_relns() AS user_relns ...@@ -587,6 +587,7 @@ SELECT user_relns() AS user_relns
copy_tbl copy_tbl
d d
d_star d_star
date_tbl
default_seq default_seq
default_tbl default_tbl
defaultexpr_tbl defaultexpr_tbl
...@@ -648,12 +649,13 @@ SELECT user_relns() AS user_relns ...@@ -648,12 +649,13 @@ SELECT user_relns() AS user_relns
tenk1 tenk1
tenk2 tenk2
text_tbl text_tbl
time_tbl
timestamp_tbl timestamp_tbl
tinterval_tbl tinterval_tbl
toyemp toyemp
varchar_tbl varchar_tbl
xacttest xacttest
(90 rows) (92 rows)
--SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer'))) AS equip_name; --SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer'))) AS equip_name;
-- --
......
--
-- DATE
--
CREATE TABLE DATE_TBL (f1 date);
INSERT INTO DATE_TBL VALUES ('1957-04-09');
INSERT INTO DATE_TBL VALUES ('1957-06-13');
INSERT INTO DATE_TBL VALUES ('1996-02-28');
INSERT INTO DATE_TBL VALUES ('1996-02-29');
INSERT INTO DATE_TBL VALUES ('1996-03-01');
INSERT INTO DATE_TBL VALUES ('1996-03-02');
INSERT INTO DATE_TBL VALUES ('1997-02-28');
INSERT INTO DATE_TBL VALUES ('1997-02-29');
INSERT INTO DATE_TBL VALUES ('1997-03-01');
INSERT INTO DATE_TBL VALUES ('1997-03-02');
INSERT INTO DATE_TBL VALUES ('2000-04-01');
INSERT INTO DATE_TBL VALUES ('2000-04-02');
INSERT INTO DATE_TBL VALUES ('2000-04-03');
INSERT INTO DATE_TBL VALUES ('2038-04-08');
INSERT INTO DATE_TBL VALUES ('2039-04-09');
INSERT INTO DATE_TBL VALUES ('2040-04-10');
SELECT f1 AS "Fifteen" FROM DATE_TBL;
SELECT f1 AS "Nine" FROM DATE_TBL WHERE f1 < '2000-01-01';
SELECT f1 AS "Three" FROM DATE_TBL
WHERE f1 BETWEEN '2000-01-01' AND '2001-01-01';
--
-- Simple math
-- Leave most of it for the horology tests
--
SELECT f1 - date '2000-01-01' AS "Days From 2K" FROM DATE_TBL;
SELECT f1 - date 'epoch' AS "Days From Epoch" FROM DATE_TBL;
SELECT date 'yesterday' - date 'today' AS "One day";
SELECT date 'today' - date 'tomorrow' AS "One day";
SELECT date 'yesterday' - date 'tomorrow' AS "Two days";
SELECT date 'tomorrow' - date 'today' AS "One day";
SELECT date 'today' - date 'yesterday' AS "One day";
SELECT date 'tomorrow' - date 'yesterday' AS "Two days";
...@@ -2,6 +2,24 @@ ...@@ -2,6 +2,24 @@
-- HOROLOGY -- HOROLOGY
-- --
--
-- date, time arithmetic
--
SELECT date '1981-02-03' + time '04:05:06' AS "Date + Time";
SELECT date '1991-02-03' + time with time zone '04:05:06 PST' AS "Date + Time PST";
SELECT date '2001-02-03' + time with time zone '04:05:06 UTC' AS "Date + Time UTC";
SELECT date '1991-02-03' + interval '2 years' AS "Add Two Years";
SELECT date '2001-12-13' - interval '2 years' AS "Subtract Two Years";
SELECT date '1991-02-03' - time '04:05:06' AS "Subtract Time";
SELECT date '1991-02-03' - time with time zone '04:05:06 UTC' AS "Subtract Time UTC";
-- --
-- timestamp, interval arithmetic -- timestamp, interval arithmetic
-- --
......
...@@ -29,6 +29,8 @@ parallel group2 ...@@ -29,6 +29,8 @@ parallel group2
test path test path
test polygon test polygon
test circle test circle
test date
test time
test interval test interval
test timestamp test timestamp
test reltime test reltime
......
...@@ -18,6 +18,8 @@ path ...@@ -18,6 +18,8 @@ path
polygon polygon
circle circle
geometry geometry
date
time
interval interval
timestamp timestamp
reltime reltime
......
--
-- TIME
--
CREATE TABLE TIME_TBL (f1 time, f2 time with time zone);
INSERT INTO TIME_TBL VALUES ('00:00', '00:00 PDT');
INSERT INTO TIME_TBL VALUES ('01:00', '01:00 PDT');
INSERT INTO TIME_TBL VALUES ('02:03', '02:03 PDT');
INSERT INTO TIME_TBL VALUES ('11:59', '11:59 PDT');
INSERT INTO TIME_TBL VALUES ('12:00', '12:00 PDT');
INSERT INTO TIME_TBL VALUES ('12:01', '12:01 PDT');
INSERT INTO TIME_TBL VALUES ('23:59', '23:59 PDT');
INSERT INTO TIME_TBL VALUES ('11:59:59.99 PM', '11:59:59.99 PM PDT');
SELECT f1 AS "Time", f2 AS "Time TZ" FROM TIME_TBL;
SELECT f1 AS "Three" FROM TIME_TBL WHERE f1 < '05:06:07';
SELECT f1 AS "Five" FROM TIME_TBL WHERE f1 > '05:06:07';
SELECT f1 AS "None" FROM TIME_TBL WHERE f1 < '00:00';
SELECT f1 AS "Eight" FROM TIME_TBL WHERE f1 >= '00:00';
--
-- TIME simple math
--
SELECT f1 + time '00:01' AS "Eight" FROM TIME_TBL;
SELECT f1 + time '01:00' AS "Eight" FROM TIME_TBL;
SELECT f1 + time '00:00:01.11' AS "Eight" FROM TIME_TBL;
SELECT f1 + time '00:00:59.99' AS "Eight" FROM TIME_TBL;
SELECT f1 - '00:01' AS "Eight" FROM TIME_TBL;
SELECT f1 - '01:00' AS "Eight" FROM TIME_TBL;
SELECT f1 - '00:00:01.11' AS "Eight" FROM TIME_TBL;
SELECT f1 - '00:00:59.99' AS "Eight" FROM TIME_TBL;
--
-- TIME WITH TIME ZONE simple math
--
/*
-- Not yet implemented
-- Thomas 2000-09-09
SELECT f2 + time '00:01' AS "" FROM TIME_TBL;
SELECT f2 + time '01:00' AS "" FROM TIME_TBL;
SELECT f2 + time '00:00:01.11' AS "" FROM TIME_TBL;
SELECT f2 + '00:00:59.99' AS "" FROM TIME_TBL;
SELECT f2 - '00:01' AS "" FROM TIME_TBL;
SELECT f2 - '01:00' AS "" FROM TIME_TBL;
SELECT f2 - '00:00:01.11' AS "" FROM TIME_TBL;
SELECT f2 - '00:00:59.99' AS "" FROM TIME_TBL;
*/
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