Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we cast the type in BigQuery?

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

like image 393
Ravindra Avatar asked Apr 05 '14 10:04

Ravindra


People also ask

What is record data type in BigQuery?

ARRAY and STRUCT or RECORD are complex data types to represent nested and repeated fields. BigQuery Nested and Repeated Fields. Nested Fields. A STRUCT or RECORD contains ordered fields each with a type and field name.


2 Answers

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.

like image 65
opensourcegeek Avatar answered Sep 16 '22 22:09

opensourcegeek


Under legacy SQL, you can cast types in BigQuery using the following functions: INTEGER(), STRING(), BOOLEAN() TIMESTAMP(), and FLOAT().

Use cast() for standard SQL (see opensourcegeek's answer).

In your case, you could write:

SELECT SQRT((INTEGER(D_o_latitude) - T_s_lat)^2+(INTEGER(D_o_longitude) - T_s_long)^2)/0.00001  FROM [datasetName.tableName] 
like image 45
Jordan Tigani Avatar answered Sep 19 '22 22:09

Jordan Tigani