I have a large table in postgres in which most of the dates are in DD-Mon-YY format but some rows do not follow this pattern and can be regarded as junk values. When I try to run any date function on this column, the query fails with the error message that this junk value is not a valid date format.
My intent is to skip the rows containing junk values by writing a case statement. I will like to process only those rows which follow the valid date format i.e. 'DD-Mon-YY'.
I have written following regex pattern for date, which is working when I test it on online regex tester but is not working on postgres. I'm new to postgres so please let me know what I'm missing here.
The following snippet returns False when I'm expecting it to return True
SELECT '23-Dec-83' ~ '^\d{2}-[a-zA-Z]{3}-\d{2}$'
t
when I had a run on my pg-9.3date
type to avoid such problems.varchar
. If the table had been created with a properdate
column you wouldn't need the cleanup now.