Merge pull request #169 from CartoDB/2202-DateToNumber-with-time-zones

Changes CDB_DateToNumber() to accept timestamps with time zones 2202
This commit is contained in:
Rafa de la Torre 2015-10-06 12:52:52 +02:00
commit 39e558f494
3 changed files with 20 additions and 0 deletions

View File

@ -13,3 +13,19 @@ 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)
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;

View File

@ -0,0 +1,2 @@
SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00'::timestamp);
SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00+05'::timestamp with time zone);

View File

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