首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >创建和替换BigQuery表

创建和替换BigQuery表
EN

Stack Overflow用户
提问于 2018-02-26 11:08:47
回答 1查看 4.3K关注 0票数 0

如何创建和替换现有的BigQuery表?我使用datalab定义BigQuery查询并将结果写入BigQuery表。

我发现的最有效的方法是:

代码语言:javascript
运行
复制
%%bq query --name helloWorld
Select * from someTable

紧接着是

代码语言:javascript
运行
复制
%%bq execute --table schemaName.destination_table --query helloWorld

但是,每次我都必须手动删除该表

在命令行中,我可以执行类似这样的命令:

代码语言:javascript
运行
复制
bq query --destination_table [PROJECT_ID]:[DATASET].[TABLE] --replace '[QUERY]'

python/Datalab中是否有类似的功能?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-27 19:05:21

使用--mode-m参数。例如:

%%bq execute --table schemaName.destination_table --query helloWorld --mode overwrite

通过运行%%bq execute --help查看更多选项

代码语言:javascript
运行
复制
usage: %bq execute [-h] [-nc] [-b BILLING] [-m {create,append,overwrite}] [-l]
                   -q QUERY [-t TABLE] [--to-dataframe]
                   [--dataframe-start-row DATAFRAME_START_ROW]
                   [--dataframe-max-rows DATAFRAME_MAX_ROWS] [-v]

Execute a BigQuery SQL query and optionally send the results to a named table.
The cell can optionally contain arguments for expanding variables in the
query.

optional arguments:
  -h, --help            show this help message and exit
  -nc, --nocache        Don't use previously cached results
  -b BILLING, --billing BILLING
                        BigQuery billing tier
  -m {create,append,overwrite}, --mode {create,append,overwrite}
                        The table creation mode
  -l, --large           Whether to allow large results
  -q QUERY, --query QUERY
                        The name of query to run
  -t TABLE, --table TABLE
                        Target table name
  --to-dataframe        Convert the result into a dataframe
  --dataframe-start-row DATAFRAME_START_ROW
                        Row of the table to start the dataframe export
  --dataframe-max-rows DATAFRAME_MAX_ROWS
                        Upper limit on number of rows to export to the
                        dataframe
  -v, --verbose         Show the expanded SQL that is being executed
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48980886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档