try_cast converts a value to a target type while returning NULL when conversion fails instead of aborting the query. This is useful when exploring nested JSON whose fields contain inconsistent values, such as a string that cannot become DOUBLE. section 5.3
Safely typing nested shot data
After unnesting the home and away shot lists, cast each row as a STRUCT with numeric X, Y, and xG fields: CREATE OR REPLACE VIEW shots AS (...) SELECT try_cast(row AS STRUCT(id BIGINT, X DOUBLE, Y DOUBLE, xG DOUBLE, ...)) AS row; Values that cannot be converted to DOUBLE become literal NULL values, allowing exploratory queries to continue. Inspect or flatten the resulting STRUCT before aggregating fields such as xG. section 5.3
Use ordinary CAST when conversion errors should expose bad data immediately; use try_cast when field-level cleanup would cost too much during exploration. section 5.3
