Google BigQuery:合并语句

时间:2018-11-29 11:24:36

标签: google-bigquery

如果表为空或using select不返回任何行,为什么此合并不运行insert语句?

MERGE INTO
  `table` TGT
USING
  (
  SELECT
    field   
  FROM
    `table`
  WHERE 
    field='1'   
 ) SOURCE
ON
  (TGT.field = SOURCE.field )
  WHEN MATCHED  THEN 
    UPDATE SET  TGT.field='value1'
  WHEN NOT MATCHED   THEN
    INSERT   (field) VALUES   ( 'value2') 

1 个答案:

答案 0 :(得分:1)

    MERGE INTO
     `table` DESTINY
    USING
     ( select 'value' as Field)  SOURCE 
    ON
     DESTINY.Field = SOURCE.Field
     WHEN MATCHED  THEN  UPDATE SET  DESTINY.Field='value 1'
     WHEN NOT MATCHED  THEN INSERT (Field) VALUES  ( 'value 2')