sql - Why is BigQuery converting some dates to timestamps but not others? -
our sql query shown below converting strings timestamp fields failing on dates , not on others. causing conversion fail?
select birthdate, timestamp(regexp_replace(birthdate, r'(..)/(..)/(....)', r'\3-\2-\1')) ts [our_project:our_table] limit 1000
here results. notice bigquery giving "null" many of dates. why regex failing? there add make more robust?
here second conversion query tried.
select birthdate, timestamp(year + '-' + month + '-' + day) output_timestamp ( select birthdate, regexp_extract(birthdate, '.*/([0-9]{4})$') year, regexp_extract(birthdate, '^([0-9]{2}).*') day, regexp_extract(birthdate, '.*/([0-9]{2})/.*') month [our_project:our_table] ) limit 1000
notice nulls appeared in these results well.
how might fix going wrong?
it turns out month , day swapped (international versus u.s.) result ranges invalid timestamp. once swapped day , month - conversions occurred without problems.
Comments
Post a Comment