Reputation: 1328
In BigQuery, let say I have an existing table with X fields. Field 1 is currently an INTEGER but I would like to change it to a STRING.
I need to keep data that is currently in Field 1, while being able to insert string data into that field.
I believe that it is currently impossible in Google BigQuery to modify the type of a column. I think that the only modification that we can do to a table is add columns with the Table.Update command
So what would be the best way do to that?
I was thinking of doing this, but I would hope that there is a better solution:
- Select STRING(field1) as field1, field2, field3, fieldX from MyTable
- Export the result in a TempTable
- Delete MyTable
- Copy TempTable to MyTable
I would then be able to insert strings in field1.
Upvotes: 6
Views: 11552
Reputation: 26637
Steps 1-4 can all be done in a single atomic step. Just set a destination table on your query and use allow_large_results and use write_truncate to write your results back to the original table. This will update your table in place.
Upvotes: 9