Skip to content

Can't parse with query inner join #1302

Closed

Description

@longht95

I have statement :
SELECT * FROM TABLE1 tb1
INNER JOIN TABLE2 tb2
INNER JOIN TABLE3 tb3
INNER JOIN TABLE4 tb4
ON (tb3.aaa = tb4.aaa)
ON (tb2.aaa = tb3.aaa)
ON (tb1.aaa = tb2.aaa)

I try :
Select select = (Select) CCJSqlParserUtil.parse("SELECT * FROM TABLE1 tb1 "
+ "INNER JOIN TABLE2 tb2 "
+ "INNER JOIN TABLE3 tb3 "
+ "INNER JOIN TABLE4 tb4 "
+ "ON (tb3.aaa = tb4.aaa) "
+ "ON (tb2.aaa = tb3.aaa) "
+ "ON (tb1.aaa = tb2.aaa)");

Expected behavior
Exception in thread "main" net.sf.jsqlparser.JSQLParserException: Encountered unexpected token: "ON" "ON"
at line 1, column 115.
System

  • Database you are using : Oracle
  • Java Version : 1.8
  • JSqlParser version : 4.1

Activity

  1. manticore-projects commented on Aug 14, 2021

    @manticore-projects
    Contributor

    Greetings.

    unfortunately I am not sure if your Statement is valid.
    Changing it into valid syntax will work:

    SELECT *
    FROM table1 tb1
        INNER JOIN (TABLE2 tb2 INNER JOIN (TABLE3 tb3 INNER JOIN TABLE4 tb4 ON tb3.aaa = tb4.aaa) ON tb2.aaa = tb3.aaa)
            ON tb1.aaa = tb2.aaa
    ;

    You can test it here online and interactively

    Please close the issue after verification.

  2. longht95 commented on Aug 14, 2021

    @longht95
    Author

    Thanks for your support,
    But this is statement is valid.
    You can check it below :
    sqlstatement
    check valid SQL oracle :
    https://www.eversql.com/sql-syntax-check-validator/

    Do you have an idea for this issue?
    Maybe, convert the statement to JSQLParse have to parse it.

  3. manticore-projects commented on Aug 14, 2021

    @manticore-projects
    Contributor

    JSQLParser does expect the extra-brackets around the nested joins, although this might be subject to a change/improvement because in fact the RDBMS do not expect these extra-brackets.

    JSQLParser does not support your initial statement.

  4. manticore-projects commented on Aug 14, 2021

    @manticore-projects
    Contributor

    according to https://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_10002.htm#BABGHCBD
    image

    my assumption on the syntax seems to be correct.

  5. manticore-projects commented on Aug 14, 2021

    @manticore-projects
    Contributor

    I have just checked in H2 and also Oracle itself

    select *
    from risk.instrument a
    inner join risk.instrument b
    inner join risk.instrument c
    on b.id_instrument=c.id_instrument
    on a.id_instrument = b.id_instrument

    It is indeed a valid statement and we will need to refactor the JOIN expressions accordingly.
    The original report is legit, thank you for reporting it.

  6. longht95 commented on Aug 14, 2021

    @longht95
    Author

    I look forward to your updates

  7. added a commit that references this issue on Aug 14, 2021
    cd4b189
  8. longht95 commented on Sep 3, 2021

    @longht95
    Author

    Dear @manticore-projects ,
    How to get a version to have the resolver

  9. manticore-projects commented on Sep 4, 2021

    @manticore-projects
    Contributor

    How to get a version to have the resolver

    Greetings, either pull from the PR (which has not been accepted yet) or use the attached unoffical snapshot I built for you.
    jsqlparser-4.2-SNAPSHOT_UNOFFICAL.jar.zip

  10. added a commit that references this issue on Sep 6, 2021
    d18c59b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions