Google bigquery bq mk-f--视图(强制替换现有视图不起作用)

Google bigquery bq mk-f--视图(强制替换现有视图不起作用),google-bigquery,Google Bigquery,似乎-f或--force=true标志不适用于视图。 因为它仍然输出以下错误 could not be created; a table with this name already exists. 下面是我使用的命令的一部分 bq mk --use_legacy_sql=false -f --description "View on reporting table ..." --view 基于文档,它仅强制创建表(如果已经存在),而不谈论视图 --force or -f When spec

似乎-f或--force=true标志不适用于视图。 因为它仍然输出以下错误

could not be created; a table with this name already exists.
下面是我使用的命令的一部分

bq mk --use_legacy_sql=false -f --description "View on reporting table ..." --view

基于文档,它仅强制创建表(如果已经存在),而不谈论视图

--force or -f
When specified, ignore already exists errors and overwrite the table without prompting. The default value is false.

您可以使用CREATE或REPLACE VIEW语句,例如

bq query --use_legacy_sql=false "
  CREATE OR REPLACE VIEW dataset.view
  OPTIONS (description='View on reporting table ...') AS
  SELECT ...
"

有关更多信息,请参阅。

实际上,根据我正在运行的一些测试,此选项不符合文档中的建议(
[…]并在不提示的情况下覆盖表),即使对于表:

$ bq mk test_dataset.test
  Table 'PROJECT:test_dataset.test' successfully created.
$ bq mk test_dataset.test
  BigQuery error in mk operation: Table 'PROJECT:test_dataset.test' could not be created; a table with this name already exists.
$ bq mk -f test_dataset.test
  Table 'PROJECT:test_dataset.test' could not be created; a table with this name already exists.
此外,在查看CLI工具的说明时,说明与文档中的说明不同:

$ bq mk --help
  [...]
  -f,--[no]force: Ignore errors reporting that the object already exists.
    (default: 'false')
事实上,如果我们在添加或不添加
-f
标志时查看命令的退出状态,我们会看到一个显著的差异:

$ bq mk test_dataset.test
  BigQuery error in mk operation: Table 'PROJECT:test_dataset.test' could not be created; a table with this name already exists.
$ echo $?
  1
$ bq mk -f test_dataset.test
  Table 'PROJECT:test_dataset.test' could not be created; a table with this name already exists.
$ echo $?
  0
因此,我认为在这种情况下,功能是正确的(正如您所看到的,当不添加标志时,输出在mk operation
中包含一条附加消息
BigQuery error,该消息不随标志出现),并且文档没有反映标志的真实行为

因此,我已经在内部报告了这一点,以便对文档进行必要的更改

关于如何使用此标志实现您试图达到的目标,您可以使用其他答案和评论中提出的任何一种变通方法,这似乎都是很好的选择


为了给这篇文章提供一些最后的上下文,已经更改了,以反映
-f
标志的真正功能:

--强制或-f

指定时,如果资源已存在,则退出代码为0。这个 默认值为false


使用
bq update
修改视图。谢谢,看来我应该使用bq更新或创建或替换DDL