mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Allow to_timestamp(float8) to convert float infinity to timestamp infinity.
With the original SQL-function implementation, such cases failed because we don't support infinite intervals. Converting the function to C lets us bypass the interval representation, which should be a bit faster as well as more flexible. Vitaly Burovoy, reviewed by Anastasia Lubennikova
This commit is contained in:
@ -2307,6 +2307,53 @@ SELECT make_timestamptz(2007, 12, 9, 3, 0, 0, 'VET');
|
||||
Sun Dec 09 07:30:00 2007 UTC
|
||||
(1 row)
|
||||
|
||||
SELECT to_timestamp( 0); -- 1970-01-01 00:00:00+00
|
||||
to_timestamp
|
||||
------------------------------
|
||||
Thu Jan 01 00:00:00 1970 UTC
|
||||
(1 row)
|
||||
|
||||
SELECT to_timestamp( 946684800); -- 2000-01-01 00:00:00+00
|
||||
to_timestamp
|
||||
------------------------------
|
||||
Sat Jan 01 00:00:00 2000 UTC
|
||||
(1 row)
|
||||
|
||||
SELECT to_timestamp(1262349296.7890123); -- 2010-01-01 12:34:56.789012+00
|
||||
to_timestamp
|
||||
-------------------------------------
|
||||
Fri Jan 01 12:34:56.789012 2010 UTC
|
||||
(1 row)
|
||||
|
||||
-- edge cases
|
||||
SELECT to_timestamp(-1e20::float8); -- error, out of range
|
||||
ERROR: timestamp out of range: "-1e+20"
|
||||
SELECT to_timestamp(-210866803200.0625); -- error, out of range
|
||||
ERROR: timestamp out of range: "-2.10867e+11"
|
||||
SELECT to_timestamp(-210866803200); -- 4714-11-24 00:00:00+00 BC
|
||||
to_timestamp
|
||||
---------------------------------
|
||||
Mon Nov 24 00:00:00 4714 UTC BC
|
||||
(1 row)
|
||||
|
||||
-- The upper boundary differs between integer and float timestamps, so check the biggest one
|
||||
SELECT to_timestamp(185331707078400::float8); -- error, out of range
|
||||
ERROR: timestamp out of range: "1.85332e+14"
|
||||
-- nonfinite values
|
||||
SELECT to_timestamp(' Infinity'::float);
|
||||
to_timestamp
|
||||
--------------
|
||||
infinity
|
||||
(1 row)
|
||||
|
||||
SELECT to_timestamp('-Infinity'::float);
|
||||
to_timestamp
|
||||
--------------
|
||||
-infinity
|
||||
(1 row)
|
||||
|
||||
SELECT to_timestamp('NaN'::float);
|
||||
ERROR: timestamp cannot be NaN
|
||||
SET TimeZone to 'Europe/Moscow';
|
||||
SELECT '2011-03-26 21:00:00 UTC'::timestamptz;
|
||||
timestamptz
|
||||
|
@ -403,6 +403,21 @@ SELECT '2007-12-09 04:00:00'::timestamp AT TIME ZONE 'VET';
|
||||
SELECT make_timestamptz(2007, 12, 9, 2, 0, 0, 'VET');
|
||||
SELECT make_timestamptz(2007, 12, 9, 3, 0, 0, 'VET');
|
||||
|
||||
SELECT to_timestamp( 0); -- 1970-01-01 00:00:00+00
|
||||
SELECT to_timestamp( 946684800); -- 2000-01-01 00:00:00+00
|
||||
SELECT to_timestamp(1262349296.7890123); -- 2010-01-01 12:34:56.789012+00
|
||||
-- edge cases
|
||||
SELECT to_timestamp(-1e20::float8); -- error, out of range
|
||||
SELECT to_timestamp(-210866803200.0625); -- error, out of range
|
||||
SELECT to_timestamp(-210866803200); -- 4714-11-24 00:00:00+00 BC
|
||||
-- The upper boundary differs between integer and float timestamps, so check the biggest one
|
||||
SELECT to_timestamp(185331707078400::float8); -- error, out of range
|
||||
-- nonfinite values
|
||||
SELECT to_timestamp(' Infinity'::float);
|
||||
SELECT to_timestamp('-Infinity'::float);
|
||||
SELECT to_timestamp('NaN'::float);
|
||||
|
||||
|
||||
SET TimeZone to 'Europe/Moscow';
|
||||
|
||||
SELECT '2011-03-26 21:00:00 UTC'::timestamptz;
|
||||
|
Reference in New Issue
Block a user