In BigQuery, I'm trying to update a column 'PSB' having all null values in table t1, from another table t2 having column 'SB'. The issue is with the Key data field while doing Left Join. The data type of key in table t1 is String and in table t2 is Integer. table1 key name: 'PC' table2 key name: 'art'
I'm using the following code:
UPDATE table1 t1
SET PSB = IFNULL(sb, null)
FROM (
SELECT cast(a.PC as INT64), b.art, b.sb
FROM table1 a
LEFT JOIN table2 b
on cast(a.PC as INT64) = b.art
) t2
WHERE t1.(cast(a.PC as INT64)) = t2.art
I'm getting following error: "Syntax error: Unexpected keyword CAST"
Where am I going wrong ?
The syntax in the
WHEREclause is off, and theCASTshould include the entire expression. Try this version:In addition, the current
WHEREclause:WHERE t1.(cast(a.PC as INT64)) = t2.art
does not make sense, since it should be correlating the two tables involved in the join. The LHS should be referring to
table1in the outer query.