From 2ceea5adb02603ef52579b568ca2c5aebed87358 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 1 Jan 2023 14:16:07 -0500 Subject: [PATCH] Accept "+infinity" in date and timestamp[tz] input. The float and numeric types accept this variant spelling of "infinity", so it seems like the datetime types should too. Vik Fearing, some cosmetic mods by me Discussion: https://postgr.es/m/d0bef637-2dbd-0a5d-e539-48243b6f6c5e@postgresfriends.org --- src/backend/utils/adt/datetime.c | 1 + src/test/regress/expected/date.out | 6 ++++++ src/test/regress/expected/timestamp.out | 6 ++++++ src/test/regress/expected/timestamptz.out | 6 ++++++ src/test/regress/sql/date.sql | 2 ++ src/test/regress/sql/timestamp.sql | 2 ++ src/test/regress/sql/timestamptz.sql | 2 ++ 7 files changed, 25 insertions(+) diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 8afda0e5d2..e0f538239f 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -105,6 +105,7 @@ const char *const days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", */ static const datetkn datetktbl[] = { /* token, type, value */ + {"+infinity", RESERV, DTK_LATE}, /* same as "infinity" */ {EARLY, RESERV, DTK_EARLY}, /* "-infinity" reserved for "early time" */ {DA_D, ADBC, AD}, /* "ad" for years > 0 */ {"allballs", RESERV, DTK_ZULU}, /* 00:00:00 */ diff --git a/src/test/regress/expected/date.out b/src/test/regress/expected/date.out index f8f83e40e9..c0dec448e1 100644 --- a/src/test/regress/expected/date.out +++ b/src/test/regress/expected/date.out @@ -1373,6 +1373,12 @@ select isfinite('infinity'::date), isfinite('-infinity'::date), isfinite('today' f | f | t (1 row) +select 'infinity'::date = '+infinity'::date as t; + t +--- + t +(1 row) + -- -- oscillating fields from non-finite date: -- diff --git a/src/test/regress/expected/timestamp.out b/src/test/regress/expected/timestamp.out index be66274738..edc6912e7a 100644 --- a/src/test/regress/expected/timestamp.out +++ b/src/test/regress/expected/timestamp.out @@ -76,6 +76,12 @@ TRUNCATE TIMESTAMP_TBL; INSERT INTO TIMESTAMP_TBL VALUES ('-infinity'); INSERT INTO TIMESTAMP_TBL VALUES ('infinity'); INSERT INTO TIMESTAMP_TBL VALUES ('epoch'); +SELECT timestamp 'infinity' = timestamp '+infinity' AS t; + t +--- + t +(1 row) + -- Postgres v6.0 standard output format INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST'); -- Variations on Postgres v6.1 standard output format diff --git a/src/test/regress/expected/timestamptz.out b/src/test/regress/expected/timestamptz.out index fb06acbccc..00379fd0fd 100644 --- a/src/test/regress/expected/timestamptz.out +++ b/src/test/regress/expected/timestamptz.out @@ -87,6 +87,12 @@ TRUNCATE TIMESTAMPTZ_TBL; INSERT INTO TIMESTAMPTZ_TBL VALUES ('-infinity'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('infinity'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('epoch'); +SELECT timestamptz 'infinity' = timestamptz '+infinity' AS t; + t +--- + t +(1 row) + -- Postgres v6.0 standard output format INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST'); -- Variations on Postgres v6.1 standard output format diff --git a/src/test/regress/sql/date.sql b/src/test/regress/sql/date.sql index 9fd15be5f9..89982dd2f8 100644 --- a/src/test/regress/sql/date.sql +++ b/src/test/regress/sql/date.sql @@ -329,6 +329,8 @@ select 'infinity'::date, '-infinity'::date; select 'infinity'::date > 'today'::date as t; select '-infinity'::date < 'today'::date as t; select isfinite('infinity'::date), isfinite('-infinity'::date), isfinite('today'::date); +select 'infinity'::date = '+infinity'::date as t; + -- -- oscillating fields from non-finite date: -- diff --git a/src/test/regress/sql/timestamp.sql b/src/test/regress/sql/timestamp.sql index e1175b12ce..1d580f77f1 100644 --- a/src/test/regress/sql/timestamp.sql +++ b/src/test/regress/sql/timestamp.sql @@ -49,6 +49,8 @@ INSERT INTO TIMESTAMP_TBL VALUES ('-infinity'); INSERT INTO TIMESTAMP_TBL VALUES ('infinity'); INSERT INTO TIMESTAMP_TBL VALUES ('epoch'); +SELECT timestamp 'infinity' = timestamp '+infinity' AS t; + -- Postgres v6.0 standard output format INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST'); diff --git a/src/test/regress/sql/timestamptz.sql b/src/test/regress/sql/timestamptz.sql index 27263b3e0b..4905dd0831 100644 --- a/src/test/regress/sql/timestamptz.sql +++ b/src/test/regress/sql/timestamptz.sql @@ -50,6 +50,8 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('-infinity'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('infinity'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('epoch'); +SELECT timestamptz 'infinity' = timestamptz '+infinity' AS t; + -- Postgres v6.0 standard output format INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');