I am trying to insert VARCHARs strings which are not a valid date format into another table where they are also stored as a VARCHAR. I'm trying to use STR_TO_DATE to accomplish this, which is supposed to return NULL if a string's format is invalid:
INSERT INTO DateErrors
SELECT `row_id`,`date_string`
FROM `source_table`
WHERE STR_TO_DATE(`date_string`,'%d-%m-%Y') IS NULL
Which throws an error for strings with an invalid date format:
Error Code: 1411. Incorrect datetime value: 'some random string that isnt a date' for function str_to_date
. Instead of throwing this error, I want these string values inserted into DateErrors.
However, running just the SELECT query returns the rows where date_string
is invalid without throwing an error.