JSqlParser icon indicating copy to clipboard operation
JSqlParser copied to clipboard

Parse sql error with offset and limit

Open ldbmcs opened this issue 3 years ago • 1 comments

Describe the bug parse sql error with offset and limit

To Reproduce Steps to reproduce the behavior:

  1. Example SQL:select * from dual OFFSET ? LIMIT ?;
  2. Parsing this SQL using JSqlParser with this statements
    @Test
    public void testParseStatements() throws Exception {
        Statements result = CCJSqlParserUtil.parseStatements(
                "select * from dual OFFSET ? LIMIT ?;");
        assertEquals("SELECT * FROM dual OFFSET ? LIMIT ?;\n", result.toString());
    }
    
  3. Exception
expected: SELECT * FROM dual OFFSET ? LIMIT ?;
but was: SELECT * FROM dual LIMIT ? OFFSET ?;

Expected behavior A clear and concise description of what you expected to happen.

System

  • Database you are using
  • Java Version 1.8
  • JSqlParser version 4.3

ldbmcs avatar Dec 22 '21 13:12 ldbmcs

Greetings.

Indeed, the order of the LIMIT and OFFSET terms is not observed, but hard-coded in the de-parser.

I am still reluctant to declare that an error, because I do not see any merit in observing the order and am not sure if all RDBMS are flexible regarding this order. Instead, I see it similar to the white-space and comments: it does not add any value to the SQL statement and won't stop the SQL statement to be executed correctly.

So to me, this is a "Won't fix".

However, if you would like to contribute a PR we certainly would accept/merge it.

manticore-projects avatar Dec 30 '21 08:12 manticore-projects

Works just fine with JSQLParser 4.6 Snapshot:

SELECT *
FROM dual
LIMIT ?
OFFSET ?
;

Closed.

manticore-projects avatar Nov 22 '22 00:11 manticore-projects