In postgresql table, I have text column where dates are stored like this:
"Created at 2015-02-12 12:33:33"
or like this:
"Created at 2015-02-14 14:03:42 by Ivan" or "Start date: 2015-02-15 08:44:08"
There is just one date in text but for some row, there isn't date value at all.
example: "Created by Igor"
I need find these date and time values and update another timestamp column with these values.
Thank you!
try this:
Note: this will work only in case, if date and time values are always in format, you posted in question.
UPDATE your_table SET
datetime_column =
CASE
WHEN text_column ~ '\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}' THEN regexp_replace(text_column, '.*(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}).*', '\1')::TIMESTAMP
END
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments