Skip to content

Second+ statement will not be parsed (as DefaultContext) if first statement is not correct #28

Open
@surister

Description

When parsing a query, if it has more than one statement, the statement of index 1+ has to start with a correct keyword to be correctly identified as an statement and therefore parsed.

For these examples the ExceptionError listener is turned off.

Ex:

sqlparse("""
    ELECT 1; -- wrong
    Begin 2; -- correct
    ELECT 2; -- wrong
""")

>>> [Statement<ELECT 1>, Statement<Begin>]
sqlparse("""
    ELECT 1; -- wrong
    Begin 2; -- correct
    SELECT 2; -- correct
""")
>>> [Statement<ELECT 1>, Statement<Begin>, Statement<SELECT 2>] 
 sqlparse("""
    ELECT 1; -- wrong
    egin 2; -- wrong
    SELECT 2; -- correct
""")

>>> [Statement<ELECT 1>]

Note in the last example how it needs a correct first keyword to keep parsing statements, even if the third 'statement' is correct, this only seems to apply from the first statement onward.

Definition of statements: https://github.com/crate/crate/blob/302c91871ca5c6b34dac07c01ef03f6f2e0017ee/libs/sql-parser/src/main/antlr/io/crate/sql/parser/antlr/SqlBaseParser.g4#L26

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggrammarFor antlr4 related grammar issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions