如何将其中一列的类型从

如何将其中一列的类型从

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

问题描述

在 BigQuery 中,假设我有一个包含 X 字段的现有表.字段 1 当前是整数,但我想将其更改为字符串.

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

我认为目前在 Google BigQuery 中无法修改列的类型.我认为我们可以对表进行的唯一修改是添加带有 Table.Update 命令

那么最好的方法是什么?

我正在考虑这样做,但我希望有更好的解决方案:

  1. 从 MyTable 中选择 STRING(field1) 作为 field1、field2、field3、fieldX
  2. 将结果导出到 TempTable
  3. 删除我的表
  4. 将 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 11:44