Can we cast the type in BigQuery?

Ravindra picture Ravindra · Apr 5, 2014 · Viewed 76.2k times · Source

Following my query :

SELECT SQRT((D_o_latitude - T_s_lat)^2+(D_o_longitude - T_s_long)^2)/0.00001 FROM [datasetName.tableName]

I am getting the error as Error: Argument type mismatch in function SUBTRACT:'D_o_latitude' is type string, 'T_s_lat' is type string

So Let me know can we convert the string type to float in the query some thing like casting the data type, I can not change the datatype

Answer

opensourcegeek picture opensourcegeek · Dec 20, 2016

With standard SQL you can use CAST function, eg. cast(numStringColumn as int64). Look out for standard SQL type names, as they aren't exactly same as legacy SQL.