2014-05-05 23:13:06 +08:00
|
|
|
-- Convert string to date
|
|
|
|
--
|
|
|
|
CREATE OR REPLACE FUNCTION CDB_StringToDate(input character varying)
|
|
|
|
RETURNS date AS $$
|
2014-06-11 17:25:25 +08:00
|
|
|
DECLARE output DATE;
|
2014-05-05 23:13:06 +08:00
|
|
|
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' STABLE STRICT;
|