问题描述
在 BigQuery 中,假设我有一个包含 X 字段的现有表.字段 1 当前是整数,但我想将其更改为字符串.
我需要保留当前在字段 1 中的数据,同时能够将字符串数据插入到该字段中.
我认为目前在 Google BigQuery 中无法修改列的类型.我认为我们可以对表进行的唯一修改是添加带有 Table.Update 命令
那么最好的方法是什么?
我正在考虑这样做,但我希望有更好的解决方案:
- 从 MyTable 中选择 STRING(field1) 作为 field1、field2、field3、fieldX
- 将结果导出到 TempTable
- 删除我的表
- 将 TempTable 复制到 MyTable
然后我就可以在 field1 中插入字符串了.
步骤 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:
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!