Skip to content

Instantly share code, notes, and snippets.

@nanounanue
Created September 19, 2018 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanounanue/25ee4be8fb07d0d873308ca7dbf293c5 to your computer and use it in GitHub Desktop.
Save nanounanue/25ee4be8fb07d0d873308ca7dbf293c5 to your computer and use it in GitHub Desktop.
validate if a is a valid date (postgresql)
-- from https://dba.stackexchange.com/a/8835/16235
create function is_valid_date(text) returns boolean language plpgsql immutable as $$
begin
return case when $1::date is null then false else true end;
exception when others then
return false;
end;$$;
-- use:
-- select case when is_valid_date(column) then column::date end from table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment