Skip to content

Snowflake MERGE statement does not require parentheses around the ON statement #1315

Closed
@stewartbryson

Description

@stewartbryson

Describe the bug
The Snowflake MERGE statement does not require the ON statement to be wrapped in parantheses.

To Reproduce
Steps to reproduce the behavior:

  1. Example SQL
MERGE INTO CONSULTANT T USING (
    SELECT
        *
    from
        CONSULTANT
) S ON S.ID = T.ID
WHEN MATCHED THEN
UPDATE
SET
    T.RESOURCE = S.RESOURCE
    WHEN NOT MATCHED THEN
INSERT
    (ID, RESOURCE)
values
    (S.ID, S.RESOURCE);
  1. Parsing this SQL using JSqlParser with these statements
String text = """
MERGE INTO CONSULTANT T USING (
    SELECT
        *
    from
        CONSULTANT
) S ON S.ID = T.ID
WHEN MATCHED THEN
UPDATE
SET
    T.RESOURCE = S.RESOURCE
    WHEN NOT MATCHED THEN
INSERT
    (ID, RESOURCE)
values
    (S.ID, S.RESOURCE);
"""
Statement query = CCJSqlParserUtil.parse(text)
  1. Exception
net.sf.jsqlparser.JSQLParserException: Encountered unexpected token: "S" <S_IDENTIFIER>
    at line 7, column 8.

Was expecting:

    "("

Expected behavior
When the parentheses are included around the ON, this works:

String text = """
MERGE INTO CONSULTANT T USING (
    SELECT
        *
    from
        CONSULTANT
) S ON (S.ID = T.ID)
WHEN MATCHED THEN
UPDATE
SET
    T.RESOURCE = S.RESOURCE
    WHEN NOT MATCHED THEN
INSERT
    (ID, RESOURCE)
values
    (S.ID, S.RESOURCE);
"""
Statement query = CCJSqlParserUtil.parse(text)

System

  • Database you are using: Snowflake
  • Java Version: 11
  • JSqlParser version: 4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions