BigQuery 命令行工具 - 使用查询附加到 table
BigQuery command line tool - append to table using query
是否可以使用 bq 命令行工具将 运行ning 查询的结果附加到 table?我看不到可用于指定它的标志,当我 运行 它失败并显示 "table already exists"
bq query --allow_large_results --destination_table=project:DATASET.table "SELECT * FROM [project:DATASET.another_table]"
BigQuery error in query operation: Error processing job '':
Already Exists: Table project:DATASET.table
最初 BigQuery 不支持标准 SQL 习语
INSERT foo SELECT a,b,c from bar where d>0;
你必须按照他们的方式使用 --append_table
但是根据@Will 的回答,现在可以了。
最初是用bq,有
bq query --append_table ...
bq查询命令的帮助是
$ bq query --help
并且输出显示前 25% 的 append_table 选项。
Python script for interacting with BigQuery.
USAGE: bq.py [--global_flags] <command> [--command_flags] [args]
query Execute a query.
Examples:
bq query 'select count(*) from publicdata:samples.shakespeare'
Usage:
query <sql_query>
Flags for query:
/home/paul/google-cloud-sdk/platform/bq/bq.py:
--[no]allow_large_results: Enables larger destination table sizes.
--[no]append_table: When a destination table is specified, whether or not to
append.
(default: 'false')
--[no]batch: Whether to run the query in batch mode.
(default: 'false')
--destination_table: Name of destination table for query results.
(default: '')
...
与其将两个表附加在一起,不如使用 UNION ALL
更好,这是 sql 的串联版本。
在大查询中,SELECT something from tableA, tableB
中两个表之间的逗号或 ,
操作是 UNION ALL
,而不是 JOIN
,或者至少它是最后一个我看的时候。
以防万一有人最终在 Google 中找到这个问题,BigQuery 自 post 以来已经发展了很多,现在 support Standard。
如果您想使用标准版的 DML syntax 功能将查询结果附加到 table,您可以这样做:
INSERT dataset.Warehouse (warehouse, state)
SELECT *
FROM UNNEST([('warehouse #1', 'WA'),
('warehouse #2', 'CA'),
('warehouse #3', 'WA')])
如 docs 中所示。
对于命令行工具它遵循同样的想法,你只需要添加标志--use_legacy_sql=False
,就像这样:
bq query --use_legacy_sql=False "insert into dataset.table (field1, field2) select field1, field2 from table"
根据当前文档(2018 年 3 月):https://cloud.google.com/bigquery/docs/loading-data-local#appending_to_or_overwriting_a_table_using_a_local_file
您应该添加:
--noreplace
或 --replace=false
是否可以使用 bq 命令行工具将 运行ning 查询的结果附加到 table?我看不到可用于指定它的标志,当我 运行 它失败并显示 "table already exists"
bq query --allow_large_results --destination_table=project:DATASET.table "SELECT * FROM [project:DATASET.another_table]"
BigQuery error in query operation: Error processing job '': Already Exists: Table project:DATASET.table
最初 BigQuery 不支持标准 SQL 习语
INSERT foo SELECT a,b,c from bar where d>0;
你必须按照他们的方式使用 --append_table
但是根据@Will 的回答,现在可以了。
最初是用bq,有
bq query --append_table ...
bq查询命令的帮助是
$ bq query --help
并且输出显示前 25% 的 append_table 选项。
Python script for interacting with BigQuery.
USAGE: bq.py [--global_flags] <command> [--command_flags] [args]
query Execute a query.
Examples:
bq query 'select count(*) from publicdata:samples.shakespeare'
Usage:
query <sql_query>
Flags for query:
/home/paul/google-cloud-sdk/platform/bq/bq.py:
--[no]allow_large_results: Enables larger destination table sizes.
--[no]append_table: When a destination table is specified, whether or not to
append.
(default: 'false')
--[no]batch: Whether to run the query in batch mode.
(default: 'false')
--destination_table: Name of destination table for query results.
(default: '')
...
与其将两个表附加在一起,不如使用 UNION ALL
更好,这是 sql 的串联版本。
在大查询中,SELECT something from tableA, tableB
中两个表之间的逗号或 ,
操作是 UNION ALL
,而不是 JOIN
,或者至少它是最后一个我看的时候。
以防万一有人最终在 Google 中找到这个问题,BigQuery 自 post 以来已经发展了很多,现在 support Standard。
如果您想使用标准版的 DML syntax 功能将查询结果附加到 table,您可以这样做:
INSERT dataset.Warehouse (warehouse, state)
SELECT *
FROM UNNEST([('warehouse #1', 'WA'),
('warehouse #2', 'CA'),
('warehouse #3', 'WA')])
如 docs 中所示。
对于命令行工具它遵循同样的想法,你只需要添加标志--use_legacy_sql=False
,就像这样:
bq query --use_legacy_sql=False "insert into dataset.table (field1, field2) select field1, field2 from table"
根据当前文档(2018 年 3 月):https://cloud.google.com/bigquery/docs/loading-data-local#appending_to_or_overwriting_a_table_using_a_local_file
您应该添加:
--noreplace
或 --replace=false