Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] JSQLParser Version 4.5: RDBMS : "Encountered unexpected token: "SELECT" <K_SELECT> at line 11, column 1." #1798

Closed
paolinho91 opened this issue May 30, 2023 · 2 comments

Comments

@paolinho91
Copy link

paolinho91 commented May 30, 2023

Always check against the Latest SNAPSHOT of JSQLParser and the Syntax Diagram

Failing SQL Feature:

  • Brief description of the failing SQL feature: method TablesNamesFinder.getTableList(statement) failed with error in title:
    "Encountered unexpected token: "SELECT" <K_SELECT> at line 11, column 1"

SQL Example:

  • Simplified Query Example, focusing on the failing feature:
    SELECT C1, SUM(N) AS N FROM ( ( SELECT C1, SUM(N) AS N FROM T1 GROUP BY C1 ) UNION ALL SELECT C1, 0 AS N FROM T2 ) GROUP BY C1

Software Information:

  • JSqlParser version: 4.5
  • Database: Oracle

Tips:

Query is very bad but works on Oracle DB. Line 11 is the "UNION ALL" SQL command.

@manticore-projects
Copy link
Contributor

manticore-projects commented May 30, 2023

Greetings!

This has been fixed in PR #1778 which will be released as JSQLParser 5 soonest.
You can try it here.

The AST will look like this:

SQL Text
 └─Statements: statement.select.PlainSelect
    ├─selectItems: statement.select.SelectItem
    │  └─Column: c1
    ├─selectItems: statement.select.SelectItem
    │  ├─expression: expression.Function
    │  │  └─ExpressionList: n
    │  └─Alias:  AS n
    ├─fromItem: statement.select.ParenthesedSelect
    │  └─select: statement.select.SetOperationList
    │     ├─selects: statement.select.ParenthesedSelect
    │     │  └─select: statement.select.PlainSelect
    │     │     ├─selectItems: statement.select.SelectItem
    │     │     │  └─Column: c1
    │     │     ├─selectItems: statement.select.SelectItem
    │     │     │  ├─expression: expression.Function
    │     │     │  │  └─ExpressionList: n
    │     │     │  └─Alias:  AS n
    │     │     ├─Table: t1
    │     │     └─groupBy: statement.select.GroupByElement
    │     │        └─ExpressionList: c1
    │     ├─selects: statement.select.PlainSelect
    │     │  ├─selectItems: statement.select.SelectItem
    │     │  │  └─Column: c1
    │     │  ├─selectItems: statement.select.SelectItem
    │     │  │  ├─LongValue: 0
    │     │  │  └─Alias:  AS n
    │     │  └─Table: t2
    │     └─UnionOp: UNION ALL
    └─groupBy: statement.select.GroupByElement
       └─ExpressionList: c1

@paolinho91
Copy link
Author

many thanks! It works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants