简体   繁体   English

使用联合查询将 bigquery 表与 google cloud postgres 表合并

[英]Merge bigquery table with google cloud postgres table with federated query

I am trying to merge a bigquery table (target) with a google cloud postgres table (source) with a federated query.我正在尝试将一个 bigquery 表(目标)与一个带有联合查询的谷歌云 postgres 表(源)合并。 However it looks like bigquery will not accept a federated query in the "using" clause.但是,bigquery 似乎不接受“using”子句中的联合查询。

Syntax error: Expected "(" or keyword SELECT or keyword WITH but got identifier "EXTERNAL_QUERY" at [3:9]

My query looks something like the below.我的查询如下所示。

MERGE bigquery_dataset.bigquery_table TARGET
USING (
    EXTERNAL_QUERY("projects/company-co/locations/us/connections/company","SELECT * FROM postgres_schema.postgres_table")
        ) SOURCE

ON target.id = source.id

WHEN MATCHED THEN ...
WHEN NOT MATCHED BY TARGET THEN ...
WHEN NOT MATCHED BY SOURCE THEN ...

Are there any known workarounds for this type of functionality?此类功能是否有任何已知的解决方法? Or is there any other way to perform this type of merge?或者还有其他方法可以执行这种类型的合并吗?

As per your requirement if you want to run federated queries in BigQuery where your external data source is located in Cloud PostgreSQL instance, you need to define the source dataset using the SQL function ie EXTERNAL_QUERY根据您的要求,如果您想在外部数据源位于 Cloud PostgreSQL 实例中的 BigQuery 中运行联合查询,则需要使用 SQL function ie EXTERNAL_QUERY定义源数据集

The error you are getting: “Syntax error: Expected "(" or keyword SELECT or keyword WITH but got identifier "EXTERNAL_QUERY" at [3:9]” is because you are missing out the SELECT statement before your EXTERNAL_QUERY.您收到的错误: “语法错误:预期的“(”或关键字 SELECT 或关键字 WITH 但在 [3:9] 处获得了标识符“EXTERNAL_QUERY””是因为您在 EXTERNAL_QUERY 之前遗漏了 SELECT 语句。

As per this doc , the syntax should be:根据此文档,语法应为:

SELECT * FROM EXTERNAL_QUERY(connection_id, external_database_query[, options]);

I tried running the federated query in BigQuery where the source is in Cloud PostgreSQL and it is working as expected.我尝试在 BigQuery 中运行联合查询,其中源位于云 PostgreSQL 中,它按预期工作。

SQL QUERY: SQL 查询:

MERGE myproject.demo.tab1 TARGET
USING (
  select * from EXTERNAL_QUERY("projects/myproject/locations/us-central1/connections/sqltobig", "SELECT * FROM entries;")
       ) SOURCE

ON target.entryID = source.entryID

WHEN MATCHED THEN
DELETE

WHEN NOT MATCHED THEN
INSERT(guestName, content, entryID)
VALUES(guestName, content, entryID)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将查询结果保存在 Cloud Storage 中的 BigQuery 表中 - Save the result of a query in a BigQuery Table, in Cloud Storage 将表从 Google BigQuery 导出到 Google Cloud Storage 时出现权限错误 - Permissions Error Exporting a table from Google BigQuery to Google Cloud Storage 如何配置从 Google BigQuery 到 Google AlloyDB 的联合查询? - How to configure federated query from Google BigQuery to Google AlloyDB? 无法对包含数字列的 Bigquery 表执行合并查询 - Not able to execute Merge query on Bigquery table which contains numeric column 使用变量调试 bigquery 联合查询 - Debugging a bigquery federated query with variables 查找在 BigQuery 中创建表的查询 - Finding the query that created a table in BigQuery 是否可以将云 sql 表连接到 bigquery? - Is it possible to join cloud sql table to bigquery? Google BigQuery 中的查询表有错误“访问被拒绝:BigQuery BigQuery:通配文件模式时权限被拒绝。” - Query table in Google BigQuery has error "Access Denied: BigQuery BigQuery: Permission denied while globbing file pattern." 如何将一个巨大的表作为一个文件从 BigQuery 导出到 Google 云存储桶中 - How to export a huge table from BigQuery into a Google cloud bucket as one file BigQuery - 使用查询将数据插入分区表 - BigQuery - Insert data into a partitioned table using a query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM