BigQuery timestamp does not support more than six decimals
Converting iso dates with timezones to BigQuery timestamp can be a hassle if the date contains more than six decimals.
select cast('2023-03-21T06:49:19.1234567+00:00' as timestamp)
One solution could be to truncate the fractional part like so
create or replace function [your_dataset].truncate_iso_timestamp_string(detailed_iso_timestamp string)
/* big query crashes with more than 6 decimals on dates
This function will truncate to 6 decimals and cast to timestamp. */
returns timestamp
as (
cast(
concat(
left(
split(detailed_iso_timestamp,'+')[offset(0)], 26),
'+',
split(detailed_iso_timestamp,'+')[offset(1)]) as timestamp)
);
Comments