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 ORDER BY in a union query #899

Closed
sivaraam opened this issue Nov 19, 2019 · 0 comments
Closed

Incorrect association of ORDER BY in a union query #899

sivaraam opened this issue Nov 19, 2019 · 0 comments
Assignees
Labels

Comments

@sivaraam
Copy link
Contributor

sivaraam commented Nov 19, 2019

Describe the bug
The ORDER BY present in 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
  1. Parsing this SQL using JSqlParser with this statements
        Select unionQuery = (Select) CCJSqlParserUtil.parse("SELECT * FROM table1 UNION SELECT * FROM table2 ORDER BY col");
        SetOperationList unionQueries = (SetOperationList) unionQuery.getSelectBody();
        System.out.println(unionQueries.getOrderByElements());
        unionQueries.getSelects().forEach(query -> {
            PlainSelect plainQuery = (PlainSelect) query;
            System.out.println(plainQuery.getOrderByElements());
        });
  1. Actual Output:
null
null
[col]

Expected behavior
The expected output is as follows:

[col]
null
null

Ref

System

  • Database you are using: PostgreSQL
  • Java Version: 11.0.3
  • JSqlParser version: 3.1
@wumpz wumpz self-assigned this Nov 20, 2019
@wumpz wumpz added the bug label Nov 20, 2019
@wumpz wumpz pinned this issue Nov 20, 2019
@wumpz wumpz closed this as completed in 9707e4f Nov 23, 2019
@wumpz wumpz unpinned this issue Nov 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants