2014-05-05 23:13:06 +08:00
|
|
|
-- Convert timestamp to double precision
|
|
|
|
--
|
2019-05-31 21:29:28 +08:00
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.CDB_DateToNumber(input timestamp)
|
2015-10-05 19:32:03 +08:00
|
|
|
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;
|
|
|
|
$$
|
2017-10-24 20:16:56 +08:00
|
|
|
LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL UNSAFE;
|
2015-10-05 19:32:03 +08:00
|
|
|
|
|
|
|
-- Convert timestamp with time zone to double precision
|
|
|
|
--
|
2019-05-31 21:29:28 +08:00
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.CDB_DateToNumber(input timestamp with time zone)
|
2014-05-05 23:13:06 +08:00
|
|
|
RETURNS double precision AS $$
|
2014-06-11 17:25:25 +08:00
|
|
|
DECLARE output double precision;
|
2014-05-05 23:13:06 +08:00
|
|
|
BEGIN
|
|
|
|
BEGIN
|
|
|
|
SELECT extract (EPOCH FROM input) INTO output;
|
|
|
|
EXCEPTION WHEN OTHERS THEN
|
|
|
|
RETURN NULL;
|
|
|
|
END;
|
|
|
|
RETURN output;
|
|
|
|
END;
|
|
|
|
$$
|
2017-10-24 20:16:56 +08:00
|
|
|
LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL UNSAFE;
|