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

Incorrect association of LIMIT and OFFSET in a union query #903

Open
sivaraam opened this issue Nov 26, 2019 · 0 comments
Open

Incorrect association of LIMIT and OFFSET in a union query #903

sivaraam opened this issue Nov 26, 2019 · 0 comments

Comments

@sivaraam
Copy link
Contributor

@sivaraam sivaraam commented Nov 26, 2019

Note: Similar to #899

Describe the bug

The LIMIT and OFFSET present at the end of a UNION query should be associated with the UNION query as a whole. Currently, it is being associated with the last SELECT query in the UNION.

To Reproduce

Steps to reproduce the behavior:

  1. Example SQL
SELECT * FROM table1 UNION SELECT * FROM table2 ORDER BY col LIMIT 4 OFFSET 5
  1. Parsing this SQL using JSqlParser with this statements
Select unionQuery = (Select) CCJSqlParserUtil.parse("SELECT * FROM table1 UNION SELECT * FROM table2 ORDER BY col LIMIT 4 OFFSET 5");
SetOperationList unionQueries = (SetOperationList) unionQuery.getSelectBody();
System.out.println("Limit: " + unionQueries.getLimit() + "; Offset: " + unionQueries.getOffset());
unionQueries.getSelects().forEach(query -> {
    PlainSelect plainQuery = (PlainSelect) query;
    System.out.println("Limit: " + plainQuery.getLimit() + "; Offset: " + plainQuery.getOffset());
});

Actual behavior

Limit: null; Offset: null
Limit: null; Offset: null
Limit:  LIMIT 4; Offset:  OFFSET 5

Expected behavior

Limit:  LIMIT 4; Offset:  OFFSET 5
Limit: null; Offset: null
Limit: null; Offset: null

Reference

System

  • Database you are using: PostgreSQL, MySQL
  • Java Version: 11.0.3
  • JSqlParser version: 3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.