BigQuery:如何将我的列中的某一列的类型从INTEGER更改为STRING? [英] BigQuery: How can I change the type of one of my column from INTEGER to STRING?

查看:123
本文介绍了BigQuery:如何将我的列中的某一列的类型从INTEGER更改为STRING?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在BigQuery中,假设我有一个带有X字段的现有表。字段1目前是INTEGER,但我想将其更改为STRING。



我需要保留当前在Field 1中的数据,同时能够将字符串数据插入到该字段中。



我相信Google BigQuery目前不可能修改某列的类型。我认为我们可以对表格进行的唯一修改是在列中添加 Table.Update命令



那么最好的办法是什么?



我想这样做,但我希望有一个更好的解决方案:



  1. 选择STRING(
  2. 将结果导出到TempTable中

  3. 删除MyTable

  4. 将字段1中的字段1,字段2,字段3,字段1
  5. 将TempTable复制到MyTable中


然后我可以在field1中插入字符串。 / p>

解决方案

步骤1-4可以在单个原子步骤中完成。只需在查询中设置目标表并使用allow_large_results并使用write_truncate将结果写回原始表。这将更新您的表格。


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.

解决方案

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.

这篇关于BigQuery:如何将我的列中的某一列的类型从INTEGER更改为STRING?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆