cartodb-4.42/lib/sql/scripts-available/CDB_StringToDate.sql
2024-04-06 05:25:13 +00:00

21 lines
540 B
PL/PgSQL

-- Convert string to date
--
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;
$$
LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL UNSAFE;