Overloads CDB_DateToNumber() and adds test

This commit is contained in:
Guido Fioravantti 2015-10-05 13:32:03 +02:00
parent e4ce12d1a3
commit 186ed34ee5
3 changed files with 20 additions and 0 deletions

View File

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

View File

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

View File

@ -0,0 +1,2 @@
915753600
915753600