在第1行第1栏遇到““ MERGE”“ MERGE”“,期望:<eof>

时间:2018-08-02 08:15:28

标签: google-bigquery legacy-sql

我们必须在BigQuery中使用旧版SQL。但是,合并在旧版SQL中不起作用。我们如何在旧版SQL中编写以下查询?

MERGE [ABC:xyz.tmp_cards] AS target_tbl 
USING [ABC:xyz.tmp_cards_1533188902] AS source_tbl 
ON target_tbl.id = source_tbl.id
WHEN MATCHED AND target_tbl.id = source_tbl.id THEN
   UPDATE SET target_tbl.id = source_tbl.id,
   target_tbl.user_id = source_tbl.user_id,
   target_tbl.expiration_date = source_tbl.expiration_date,
   target_tbl.created_at = source_tbl.created_at,
   target_tbl.updated_at = source_tbl.updated_at 
WHEN NOT MATCHED THEN 
   INSERT (id, user_id, expiration_date, created_at, updated_at) 
   VALUES (source_tbl.id, source_tbl.user_id, source_tbl.expiration_date, source_tbl.created_at, source_tbl.updated_at)

1 个答案:

答案 0 :(得分:1)

支持DML MERGE语句appeared in Beta just this year for standard SQL。在旧版SQL中无法做到这一点,这就是为什么Standard SQL is the preferred SQL dialect用于查询存储在BigQuery中的数据的原因。因为新功能用于BigQuery的最后一个DML,而不是旧功能。