BigQuery: How can I change the type of one of my columns from INTEGER to STRING?

In BigQuery, let's say I have an existing table with X fields. Field 1 is currently INTEGER, but I would like to change it to STRING.

I need to save the data that is currently in field 1, as well as the ability to insert string data into this field.

I believe that in Google BigQuery it is not possible to change the type of a column. I think the only modification we can do with the table is to add columns using the Table.Update command

So what would be best with this?

I thought about this, but I hope there is a better solution:

  • Select STRING (field1) as field1, field2, field3, fieldX from MyTable
  • Export result to TempTable
  • Remove MyTable
  • Copy TempTable to MyTable

Then I could insert rows into field1.

+5
google-bigquery
source share
1 answer

Steps 1-4 can be performed in one atomic step. Just set the destination table in your query and use allow_large_results and use write_truncate to return the results to the original table. This will update your table in place.

+7
source share

All Articles