Skip to content

LIMIT is misplaced when placed at the bottom of a UNION query #1018

Description

@tomershay

Describe the bug
CCJSqlParserUtil.parse() misplaces the LIMIT clause when parsing a UNION query (tested both in the object structure and in the string output).

To Reproduce
Steps to reproduce the behavior:

  1. Example SQL:
select col from tbl
union distinct
select col2 from tbl
order by test limit 100;
  1. Parsing this SQL using JSqlParser results in the following statement (note that the LIMIT now shows before the ORDER BY, which is misplaced and causes a syntax error when using the query):
SELECT tbl.col FROM tbl
UNION DISTINCT 
SELECT tbl.col2 FROM tbl 
LIMIT 100 ORDER BY test

Expected behavior
The LIMIT should be shown after the ORDER BY clause

System
Tested on PostgreSQL, but I assume the same issue will occur for other databases such as MySQL, as the SQL syntax isn't valid.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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