Skip to content

[BUG] BigQuery statement MERGE ... WHEN NOT MATCHED BY TARGET #2421

@il-bert

Description

@il-bert

Grammar or Syntax Description

  • BigQuery in the "merge ... when not matched " allows to define when it's not matched by target or by source
    currently jsqlparser is failing with these kind of statemnt stating UnsupportedStatement

https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement

when_clause ::= matched_clause | not_matched_by_target_clause | not_matched_by_source_clause
matched_clause ::= WHEN MATCHED [ AND search_condition ] THEN { merge_update_clause | merge_delete_clause }
not_matched_by_target_clause ::= WHEN NOT MATCHED [BY TARGET] [ AND search_condition ] THEN merge_insert_clause
not_matched_by_source_clause ::= WHEN NOT MATCHED BY SOURCE [ AND search_condition ] THEN { merge_update_clause | merge_delete_clause }

SQL Example

MERGE INTO target_table AS tt
USING ( SELECT key, field FROM source_table) AS st
ON tt.key = st.key
WHEN NOT MATCHED BY TARGET THEN
    INSERT (key, field)
    VALUES (st.key, st.field)
WHEN NOT MATCHED BY SOURCE THEN DELETE
;

can it be included?

thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions