Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

  1. Select STRING(field1) as field1, field2, field3, fieldX from MyTable
  2. Export the result in a TempTable
  3. Delete MyTable
  4. Copy TempTable to MyTable

I would then be able to insert strings in field1.

like image 371
YABADABADOU Avatar asked May 16 '14 20:05

YABADABADOU


People also ask

How do you transpose a column in BigQuery?

For Transpose the data first of all we have to split the value data based on “;” once we split the value column then will get and array let's take the alias of that column is keyvalue. After that will unnest the array and split the data based '=' and will create 2 column (Key and value).

How do I change the text schema in BigQuery?

In the Schema section, enter the schema definition. Option 1: Use Add field and specify each field's name, type, and mode. Option 2: Click Edit as text and paste the schema in the form of a JSON array. When you use a JSON array, you generate the schema using the same process as creating a JSON schema file.


1 Answers

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.

like image 159
Jordan Tigani Avatar answered Nov 15 '22 09:11

Jordan Tigani