在Bigquery中单独复制表结构 [英] Copy table structure alone in Bigquery

查看:77
本文介绍了在Bigquery中单独复制表结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google的Big查询中,有没有一种方法可以克隆(仅复制结构)不包含数据的表?

In Google's Big query, is there a way to clone (copy the structure alone) a table without data?

bq cp似乎没有复制没有数据的结构的选项. 具有过滤器(例如"1 = 2")的创建表为选择表(CTAS)"确实会创建不包含数据的表.但是,它不会复制分区/集群属性.

bq cp doesn't seem to have an option to copy structure without data. And Create table as Select (CTAS) with filter such as "1=2" does create the table without data. But, it doesn't copy the partitioning/clustering properties.

推荐答案

如果要克隆表的结构以及分区/集群属性,而又不需要知道确切的分区/集群属性是什么,请执行以下步骤:

If you want to clone structure of table along with partitioning/clustering properties w/o having need in knowing what exactly those partitioning/clustering properties - follow below steps:

步骤1 :只需将your_table复制到新表中-假设your_table_copy.显然,这将复制整个表,包括所有属性(包括描述,分区的到期时间等-如果您尝试手动设置它们,则很容易错过)和数据.注意:复制是免费的操作

Step 1: just copy your_table to new table - let's say your_table_copy. This will obviously copy whole table including all properties (including such like descriptions, partition's expiration etc. - which is very simple to miss if you will try to set them manually) and data. Note: copy is cost free operation

第2步:要清除新创建的表中的数据-在查询语句下运行

Step 2: To get rid of data in newly created table - run below query statement

SELECT * FROM `project.dataset.your_table_copy` LIMIT 0    

在上面运行

时,请确保将project.dataset.your_table_copy设置为目标表,并将'Overwrite Table'设置为'Write Preference'.注意:这也是免费的步骤(因为LIMIT 0)

while running above make sure you set project.dataset.your_table_copy as destination table with 'Overwrite Table' as 'Write Preference'. Note: this is also cost free step (because of LIMIT 0)

您可以在Web UI或命令行或API或您选择的任何客户端中轻松完成上述两个步骤,无论您最喜欢什么

You can easily do both above steps from within Web UI or Command Line or API or any client of your choice - whatever you are most comfortable with

这篇关于在Bigquery中单独复制表结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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