How to alter datatype of a column in BigQuery

Viewed 2916

I'm trying to change the datatype for a column in my bigquery table from INT64 to STRING with the condition it's not NULL. When I type:

ALTER TABLE table_name ALTER COLUMN id STRING NOT NULL

I get an error

Syntax error: Expected keyword DROP or keyword SET but got identifier "STRING"

How should I resolve this?

1 Answers

It is unsupported to change a column's data type at the moment.

Take a look at the official documentation. It explains 2 ways to manually change a column's data type. For the record:

  • Using a SQL query: choose this option if you are more concerned about simplicity and ease of use, and you are less concerned about costs.
  • Recreating the table: choose this option if you are more concerned about costs, and you are less concerned about simplicity and ease of use.
Related