Created
September 19, 2018 21:34
-
-
Save nanounanue/25ee4be8fb07d0d873308ca7dbf293c5 to your computer and use it in GitHub Desktop.
validate if a is a valid date (postgresql)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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