[英]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.