将视图移动到另一个Project Bigquery

时间:2018-04-17 01:33:16

标签: google-cloud-platform google-bigquery views

希望能够将视图从一个项目移动(复制和替换)到另一个项目。

假设我们有Dev GCP项目1,以及集成和生产GCP项目。我希望能够将单个视图或特定数据集(不是表格)从Dev移动到Int,然后移动到Int到Prod。

我知道我可以使用以下Google Cloud Shell命令移动表格。

bq cp ProjectNumberDev.DatasetDev.TableDev ProjectNumberInt.DatasetInt.TableInt

但是,此命令仅适用于表而不是视图,有没有办法用视图执行此操作?或者是Table Insert / Post API脚本的唯一方法?

1 个答案:

答案 0 :(得分:3)

Per documentation:

Currently, there is no supported method for copying a view from one dataset to another. You must recreate the view in the target dataset.

You can copy the SQL query from the old view:

Issue the bq show command.
The "${default[3]}" flag can be used to control the output. If you are getting information about a view in a project other than your default project, add the project ID to the dataset in the following format: --format. To write the view properties to a file, add > [PROJECT_ID]:[DATASET] to the command.

[PATH_TO_FILE]

Meantime, if you can script all your views during the development then you can use CREATE VIEW statement in all environments

See more for Data Definition Language

You can apply same approach for tables creation, etc.