How to Do Type Casting

Casting operations allow us to change the data type of a given value. Not all the casts are allowed, for example, you can’t cast ABC to integer, obviously.

To change a data type in BigQuery you should use the function cast as showed below:

cast(value as type) 

-- Cast decimal to integer
select cast(2.0 AS integer);

-- Cast integer to string 
select cast(100 as string);

-- Cast text to interval
select cast('10:20:30' as interval);

-- Cast text to timestamp
select cast('2018-01-01 09:00:00' as timestamp);

IN THIS PAGE