Question

I have a table in BigQuery with Xday, Xmonth, and Xyear columns but the data was user generated and apparently done without adequate input validation so some of it is nonsense. It's easy enough to do things like Xday between 1 and 31, but I still get an error when doing date(Xyear, Xmonth, Xday) if for example someone put in February 30th.

Is there some way I can either validate the date prior to doing the conversion to the date type or a way to just toss out the rows causing errors instead of throwing the exception?

Was it helpful?

Solution

You can add the prefix SAFE so the DATE function returns NULL instead of throwing an error.

https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top