Overloads CDB_DateToNumber() and adds test
This commit is contained in:
@@ -1,5 +1,21 @@
|
|||||||
-- Convert timestamp to double precision
|
-- Convert timestamp to double precision
|
||||||
--
|
--
|
||||||
|
CREATE OR REPLACE FUNCTION CDB_DateToNumber(input timestamp)
|
||||||
|
RETURNS double precision AS $$
|
||||||
|
DECLARE output double precision;
|
||||||
|
BEGIN
|
||||||
|
BEGIN
|
||||||
|
SELECT extract (EPOCH FROM input) INTO output;
|
||||||
|
EXCEPTION WHEN OTHERS THEN
|
||||||
|
RETURN NULL;
|
||||||
|
END;
|
||||||
|
RETURN output;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE 'plpgsql' STABLE STRICT;
|
||||||
|
|
||||||
|
-- Convert timestamp with time zone to double precision
|
||||||
|
--
|
||||||
CREATE OR REPLACE FUNCTION CDB_DateToNumber(input timestamp with time zone)
|
CREATE OR REPLACE FUNCTION CDB_DateToNumber(input timestamp with time zone)
|
||||||
RETURNS double precision AS $$
|
RETURNS double precision AS $$
|
||||||
DECLARE output double precision;
|
DECLARE output double precision;
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00+00'::timestamp);
|
||||||
|
SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00+00'::timestamp with time zone);
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
915753600
|
||||||
|
915753600
|
||||||
Reference in New Issue
Block a user