cartodb-postgresql/scripts-available/CDB_StringToDate.sql

21 lines
540 B
MySQL
Raw Normal View History

-- Convert string to date
--
2019-05-31 21:29:28 +08:00
DROP FUNCTION IF EXISTS @extschema@.CDB_StringToDate(character varying);
CREATE OR REPLACE FUNCTION @extschema@.CDB_StringToDate(input character varying)
RETURNS TIMESTAMP AS $$
DECLARE output TIMESTAMP;
BEGIN
BEGIN
output := input::date;
EXCEPTION WHEN OTHERS THEN
BEGIN
SELECT to_timestamp(input::integer) INTO output;
EXCEPTION WHEN OTHERS THEN
RETURN NULL;
END;
END;
RETURN output;
END;
$$
2017-10-24 20:16:56 +08:00
LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL UNSAFE;