Skip to content

Nested WITH statements throws error #1186

@frsann

Description

@frsann

Describe the bug
Nested WITH statements throws an parsing error. nested with statements might not be the best practice, but it's at least supported in Snowflake.

To Reproduce
Run test:

    @Test
    public void testGetTableListWithStmtFails() throws Exception {
        String sql = "WITH TESTSTMT1 AS ( WITH TESTSTMT2 AS (SELECT * FROM MY_TABLE2) SELECT col1, col2 FROM TESTSTMT2) SELECT * FROM TESTSTMT";
        net.sf.jsqlparser.statement.Statement statement = pm.parse(new StringReader(sql));

        Select selectStatement = (Select) statement;
        TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
        List<String> tableList = tablesNamesFinder.getTableList(selectStatement);
        assertEquals(2, tableList.size());
        assertEquals("MY_TABLE1", tableList.get(0));
        assertEquals("MY_TABLE2", tableList.get(1));
    }

Expected behavior
The test should more or less pass, or at least not throw an error.

System

  • Database you are using: Snowflkae
  • Java Version:openjdk version "1.8.0_232"
  • 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