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
This commit is contained in:
Tom Lane 2023-01-01 14:16:07 -05:00
parent d747dc85ae
commit 2ceea5adb0
7 changed files with 25 additions and 0 deletions

View File

@ -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 */

View File

@ -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:
--

View File

@ -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

View File

@ -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

View File

@ -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:
--

View File

@ -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');

View File

@ -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');