Skip to content

Commit

Permalink
[YSQL][#558] Reenable missing part of yb_pg_timestamp test
Browse files Browse the repository at this point in the history
Summary:
Test succeeds now, so #558 is fixed

Also roll PG timestamp test back to its original state, was changed in b58c985

Test Plan: ./yb_build.sh --java-test TestPgRegressTypesMisc

Reviewers: mbautin, mihnea, myang

Reviewed By: myang

Subscribers: myang, yql

Differential Revision: https://phabricator.dev.yugabyte.com/D15778
  • Loading branch information
def- committed Mar 16, 2022
1 parent ad91023 commit 71b760e
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 46 deletions.
127 changes: 100 additions & 27 deletions src/postgres/src/test/regress/expected/yb_pg_timestamp.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,79 @@
-- TIMESTAMP
--
CREATE TABLE TIMESTAMP_TBL (i int PRIMARY KEY, d1 timestamp(2) without time zone);
-- Test shorthand input values
-- We can't just "select" the results since they aren't constants; test for
-- equality instead. We can do that by running the test inside a transaction
-- block, within which the value of 'now' shouldn't change. We also check
-- that 'now' *does* change over a reasonable interval such as 100 msec.
-- NOTE: it is possible for this part of the test to fail if the transaction
-- block is entered exactly at local midnight; then 'now' and 'today' have
-- the same values and the counts will come out different.
INSERT INTO TIMESTAMP_TBL VALUES (10, 'now');
SELECT pg_sleep(0.1);
pg_sleep
----------

(1 row)

BEGIN;
INSERT INTO TIMESTAMP_TBL VALUES (20, 'now');
INSERT INTO TIMESTAMP_TBL VALUES (30, 'today');
INSERT INTO TIMESTAMP_TBL VALUES (40, 'yesterday');
INSERT INTO TIMESTAMP_TBL VALUES (50, 'tomorrow');
-- time zone should be ignored by this data type
INSERT INTO TIMESTAMP_TBL VALUES (60, 'tomorrow EST');
INSERT INTO TIMESTAMP_TBL VALUES (70, 'tomorrow zulu');
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'today';
one
-----
1
(1 row)

SELECT count(*) AS Three FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'tomorrow';
three
-------
3
(1 row)

SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'yesterday';
one
-----
1
(1 row)

SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now';
one
-----
1
(1 row)

COMMIT;
DELETE FROM TIMESTAMP_TBL;
-- verify uniform transaction time within transaction block
BEGIN;
INSERT INTO TIMESTAMP_TBL VALUES (10, 'now');
SELECT pg_sleep(0.1);
pg_sleep
----------

(1 row)

INSERT INTO TIMESTAMP_TBL VALUES (20, 'now');
SELECT pg_sleep(0.1);
pg_sleep
----------

(1 row)

SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now';
two
-----
2
(1 row)

COMMIT;
DELETE FROM TIMESTAMP_TBL;
-- Special values
INSERT INTO TIMESTAMP_TBL VALUES (10, '-infinity');
INSERT INTO TIMESTAMP_TBL VALUES (20, 'infinity');
Expand Down Expand Up @@ -1531,7 +1604,7 @@ SELECT '' AS to_char_12, to_char(d, 'FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff
('2018-11-02 12:34:56.78901'),
('2018-11-02 12:34:56.78901234')
) d(d);
to_char_12 | to_char
to_char_12 | to_char
------------+--------------------------------------------------------------------
| 0 00 000 0000 00000 000000 0 00 000 0000 00000 000000 000 000000
| 7 78 780 7800 78000 780000 7 78 780 7800 78000 780000 780 780000
Expand All @@ -1544,35 +1617,35 @@ SELECT i,
to_char(i * interval '1mon', 'rm'),
to_char(i * interval '1mon', 'RM')
FROM generate_series(-13, 13) i;
i | to_char | to_char
i | to_char | to_char
-----+---------+---------
-13 | xii | XII
-12 | i | I
-11 | ii | II
-10 | iii | III
-9 | iv | IV
-8 | v | V
-7 | vi | VI
-6 | vii | VII
-13 | xii | XII
-12 | i | I
-11 | ii | II
-10 | iii | III
-9 | iv | IV
-8 | v | V
-7 | vi | VI
-6 | vii | VII
-5 | viii | VIII
-4 | ix | IX
-3 | x | X
-2 | xi | XI
-1 | xii | XII
0 | |
1 | i | I
2 | ii | II
3 | iii | III
4 | iv | IV
5 | v | V
6 | vi | VI
7 | vii | VII
-4 | ix | IX
-3 | x | X
-2 | xi | XI
-1 | xii | XII
0 | |
1 | i | I
2 | ii | II
3 | iii | III
4 | iv | IV
5 | v | V
6 | vi | VI
7 | vii | VII
8 | viii | VIII
9 | ix | IX
10 | x | X
11 | xi | XI
12 | xii | XII
13 | i | I
9 | ix | IX
10 | x | X
11 | xi | XI
12 | xii | XII
13 | i | I
(27 rows)

-- timestamp numeric fields constructor
Expand Down
47 changes: 28 additions & 19 deletions src/postgres/src/test/regress/sql/timestamp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- TIMESTAMP
--

CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone PRIMARY KEY);
CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone);

-- Test shorthand input values
-- We can't just "select" the results since they aren't constants; test for
Expand All @@ -16,6 +16,8 @@ CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone PRIMARY KEY);
INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);

BEGIN;

INSERT INTO TIMESTAMP_TBL VALUES ('now');
INSERT INTO TIMESTAMP_TBL VALUES ('today');
INSERT INTO TIMESTAMP_TBL VALUES ('yesterday');
Expand All @@ -24,20 +26,25 @@ INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow EST');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow zulu');

SElECT COUNT(*) FROM TIMESTAMP_TBL;
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'today';
SELECT count(*) AS Three FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'tomorrow';
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'yesterday';
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now';

DROP TABLE TIMESTAMP_TBL;
CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone PRIMARY KEY);
COMMIT;

DELETE FROM TIMESTAMP_TBL;

-- verify uniform transaction time within transaction block
BEGIN;
INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);
INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);
SELECT count(*) FROM TIMESTAMP_TBL ORDER BY d1;
SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now';
COMMIT;

DROP TABLE TIMESTAMP_TBL;
CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone PRIMARY KEY);
DELETE FROM TIMESTAMP_TBL;

-- Special values
INSERT INTO TIMESTAMP_TBL VALUES ('-infinity');
Expand Down Expand Up @@ -134,7 +141,7 @@ INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2001');
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 "64", d1 FROM TIMESTAMP_TBL ORDER BY d1;
SELECT '' AS "64", d1 FROM TIMESTAMP_TBL;

-- Check behavior at the lower boundary of the timestamp range
SELECT '4714-11-24 00:00:00 BC'::timestamp;
Expand Down Expand Up @@ -189,37 +196,37 @@ SELECT '' AS "54", d1 as "timestamp",

-- TO_CHAR()
SELECT '' AS to_char_1, to_char(d1, 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon')
FROM TIMESTAMP_TBL ORDER BY d1;
FROM TIMESTAMP_TBL;

SELECT '' AS to_char_2, to_char(d1, 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth FMRM')
FROM TIMESTAMP_TBL ORDER BY d1;
FROM TIMESTAMP_TBL;

SELECT '' AS to_char_3, to_char(d1, 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J')
FROM TIMESTAMP_TBL ORDER BY d1;
FROM TIMESTAMP_TBL;

SELECT '' AS to_char_4, to_char(d1, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMD FMJ')
FROM TIMESTAMP_TBL ORDER BY d1;
FROM TIMESTAMP_TBL;

SELECT '' AS to_char_5, to_char(d1, 'HH HH12 HH24 MI SS SSSS')
FROM TIMESTAMP_TBL ORDER BY d1;
FROM TIMESTAMP_TBL;

SELECT '' AS to_char_6, to_char(d1, E'"HH:MI:SS is" HH:MI:SS "\\"text between quote marks\\""')
FROM TIMESTAMP_TBL ORDER BY d1;
FROM TIMESTAMP_TBL;

SELECT '' AS to_char_7, to_char(d1, 'HH24--text--MI--text--SS')
FROM TIMESTAMP_TBL ORDER BY d1;
FROM TIMESTAMP_TBL;

SELECT '' AS to_char_8, to_char(d1, 'YYYYTH YYYYth Jth')
FROM TIMESTAMP_TBL ORDER BY d1;
FROM TIMESTAMP_TBL;

SELECT '' AS to_char_9, to_char(d1, 'YYYY A.D. YYYY a.d. YYYY bc HH:MI:SS P.M. HH:MI:SS p.m. HH:MI:SS pm')
FROM TIMESTAMP_TBL ORDER BY d1;
FROM TIMESTAMP_TBL;

SELECT '' AS to_char_10, to_char(d1, 'IYYY IYY IY I IW IDDD ID')
FROM TIMESTAMP_TBL ORDER BY d1;
FROM TIMESTAMP_TBL;

SELECT '' AS to_char_11, to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID')
FROM TIMESTAMP_TBL ORDER BY d1;
FROM TIMESTAMP_TBL;

SELECT '' AS to_char_12, to_char(d, 'FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 MS US')
FROM (VALUES
Expand All @@ -237,3 +244,5 @@ SELECT i,

-- timestamp numeric fields constructor
SELECT make_timestamp(2014,12,28,6,30,45.887);

DROP TABLE TIMESTAMP_TBL;
42 changes: 42 additions & 0 deletions src/postgres/src/test/regress/sql/yb_pg_timestamp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,48 @@

CREATE TABLE TIMESTAMP_TBL (i int PRIMARY KEY, d1 timestamp(2) without time zone);

-- Test shorthand input values
-- We can't just "select" the results since they aren't constants; test for
-- equality instead. We can do that by running the test inside a transaction
-- block, within which the value of 'now' shouldn't change. We also check
-- that 'now' *does* change over a reasonable interval such as 100 msec.
-- NOTE: it is possible for this part of the test to fail if the transaction
-- block is entered exactly at local midnight; then 'now' and 'today' have
-- the same values and the counts will come out different.

INSERT INTO TIMESTAMP_TBL VALUES (10, 'now');
SELECT pg_sleep(0.1);

BEGIN;

INSERT INTO TIMESTAMP_TBL VALUES (20, 'now');
INSERT INTO TIMESTAMP_TBL VALUES (30, 'today');
INSERT INTO TIMESTAMP_TBL VALUES (40, 'yesterday');
INSERT INTO TIMESTAMP_TBL VALUES (50, 'tomorrow');
-- time zone should be ignored by this data type
INSERT INTO TIMESTAMP_TBL VALUES (60, 'tomorrow EST');
INSERT INTO TIMESTAMP_TBL VALUES (70, 'tomorrow zulu');

SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'today';
SELECT count(*) AS Three FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'tomorrow';
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'yesterday';
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now';

COMMIT;

DELETE FROM TIMESTAMP_TBL;

-- verify uniform transaction time within transaction block
BEGIN;
INSERT INTO TIMESTAMP_TBL VALUES (10, 'now');
SELECT pg_sleep(0.1);
INSERT INTO TIMESTAMP_TBL VALUES (20, 'now');
SELECT pg_sleep(0.1);
SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now';
COMMIT;

DELETE FROM TIMESTAMP_TBL;

-- Special values
INSERT INTO TIMESTAMP_TBL VALUES (10, '-infinity');
INSERT INTO TIMESTAMP_TBL VALUES (20, 'infinity');
Expand Down

0 comments on commit 71b760e

Please sign in to comment.