BigQuery Alter column change datatype
To change the data type of a column in a table in BigQuery to a less restrictive data type. For example, a NUMERIC data type can be changed to a BIGNUMERIC type but not the reverse
Alter column change datatype example
The following example changes the data type of column col1 from an INT64 to NUMERIC:
ALTER TABLE dataset.table ALTER COLUMN col1 SET DATA TYPE NUMERIC;
Explanation
You can also coerce data types from more restrictive to less restrictive parameterized data types. For example, you can increase the maximum length of a string type or increase the precision or scale of a numeric type.
For example
- NUMERIC(6,10) to NUMERIC(8,12)
- NUMERIC to BIGNUMERIC(40, 20)
- STRING(5) to STRING(7)
Syntax reference
ALTER TABLE [IF EXISTS] table_name ALTER COLUMN [IF EXISTS] column_name SET DATA TYPE data_type