Skip to content

Commit f2a9e20

Browse files
author
Thomas G. Lockhart
committed
Test for "current" time by comparing against "now".
1 parent 98462b7 commit f2a9e20

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/test/regress/expected/datetime.out

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,28 @@ one
3636
1
3737
(1 row)
3838

39-
QUERY: INSERT INTO DATETIME_TBL VALUES ('current');
40-
QUERY: BEGIN;
41-
QUERY: INSERT INTO DATETIME_TBL VALUES ('now');
39+
QUERY: SELECT 'now'::datetime - 'current'::datetime AS ZeroSecs;
40+
zerosecs
41+
--------
42+
@ 0
43+
(1 row)
44+
4245
QUERY: SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = 'now'::datetime;
4346
one
4447
---
4548
1
4649
(1 row)
4750

51+
QUERY: DELETE FROM DATETIME_TBL;
52+
QUERY: INSERT INTO DATETIME_TBL VALUES ('current');
53+
QUERY: BEGIN;
54+
QUERY: INSERT INTO DATETIME_TBL VALUES ('now');
55+
QUERY: SELECT count(*) AS two FROM DATETIME_TBL WHERE d1 = 'now'::datetime;
56+
two
57+
---
58+
2
59+
(1 row)
60+
4861
QUERY: END;
4962
QUERY: DELETE FROM DATETIME_TBL;
5063
QUERY: INSERT INTO DATETIME_TBL VALUES ('invalid');

src/test/regress/sql/datetime.sql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
CREATE TABLE DATETIME_TBL( d1 datetime);
44

55
-- Shorthand values
6-
-- Not testable since these are not constant for regression testing.
6+
-- Not directly testable since these are not constant for regression testing.
77
-- So, just try to test parser and hope for the best - tgl 97/04/26
88
INSERT INTO DATETIME_TBL VALUES ('current');
99
INSERT INTO DATETIME_TBL VALUES ('now');
@@ -19,10 +19,15 @@ SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = 'yesterday'::datetime;
1919
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = 'today'::datetime + '1 day'::timespan;
2020
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = 'today'::datetime - '1 day'::timespan;
2121

22+
SELECT 'now'::datetime - 'current'::datetime AS ZeroSecs;
23+
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = 'now'::datetime;
24+
DELETE FROM DATETIME_TBL;
25+
26+
-- verify uniform transaction time within transaction block
2227
INSERT INTO DATETIME_TBL VALUES ('current');
2328
BEGIN;
2429
INSERT INTO DATETIME_TBL VALUES ('now');
25-
SELECT count(*) AS one FROM DATETIME_TBL WHERE d1 = 'now'::datetime;
30+
SELECT count(*) AS two FROM DATETIME_TBL WHERE d1 = 'now'::datetime;
2631
END;
2732
DELETE FROM DATETIME_TBL;
2833

0 commit comments

Comments
 (0)