BigQuery 等效于“CREATE TABLE my_table (LIKE your_table)"; [英] BigQuery Equivalent of "CREATE TABLE my_table (LIKE your_table)"

查看:19
本文介绍了BigQuery 等效于“CREATE TABLE my_table (LIKE your_table)";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个表,其架构与另一个表完全相同.在其他 SQL 引擎中,我想我可以使用CREATE TABLE my_table (LIKE your_table)"或一些变体.

I want to create a table which schema is exactly the same as another table. In other SQL engines, I think I was able to use "CREATE TABLE my_table (LIKE your_table)" or some variations.

我还没有在 BigQuery 中找到等价物.这可能以某种方式实现吗?

I couldn't find the equivalent in BigQuery yet. Is this possible in some fashion?

推荐答案

使用这个表格:

CREATE TABLE dataset.new_table AS
SELECT *
FROM dataset.existing_table
LIMIT 0

这将创建一个与旧表具有相同架构的新表,并且由于 LIMIT 0 而没有成本.

This creates a new table with the same schema as the old one, and there is no cost due to the LIMIT 0.

请注意,这不会保留分区、表描述等.另一种选择是使用 CLI(或 API),制作表格的副本,然后覆盖其内容,例如:

Note that this does not preserve partitioning, table description, etc., however. Another option is to use the CLI (or API), making a copy of the table and then overwriting its contents, e.g.:

$ bq cp dataset.existing_table dataset.new_table
$ bq query --use_legacy_sql --replace --destination_table=dataset.new_table 
    "SELECT * FROM dataset.new_table LIMIT 0;"

现在新表具有与原始表相同的结构和属性.

Now the new table has the same structure and attributes as the original did.

这篇关于BigQuery 等效于“CREATE TABLE my_table (LIKE your_table)";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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