Skip to content

[BUG] JSQLParser 5.4-SNAPSHOT : RDBMS : SELECT without FROM silently drops GROUP BY / HAVING / WINDOW / QUALIFY / CONNECT BY / PREFERRING in toString() #2483

Description

@fudianchn

Failing SQL Feature:

SELECT without a FROM clause parses fine (supported Standard SQL, see #1514), but PlainSelect.toString() silently drops every clause after the select items except WHERE / PREWHERE: GROUP BY, HAVING, WINDOW, QUALIFY, START WITH / CONNECT BY and PREFERRING are all stored on the AST yet disappear from the output. A parse -> toString -> reparse round trip silently rewrites the statement.

The StatementDeParser path already renders all of them (SelectDeParser prints the whole clause chain outside its getFromItem() != null block), so the two render paths disagree.

Root cause: PlainSelect.appendSelectBodyTo (src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java): the shared clause chain lives inside the fromItem != null branch, while the else // without from branch prints preWhere / where only.

SQL Example:

SELECT 1 GROUP BY 1 HAVING 1 = 1
SELECT 1 QUALIFY 1 = 1
SELECT 1 WINDOW w AS (ORDER BY 1)
SELECT 1 START WITH 1 = 1 CONNECT BY LEVEL <= 1
SELECT 1 PREFERRING HIGH 1

All five parse on current master (ad69ecc), and each toString() returns SELECT 1:

IN : SELECT 1 GROUP BY 1 HAVING 1=1
OUT: SELECT 1

IN : SELECT 1 WINDOW w AS (ORDER BY 1)
OUT: SELECT 1

IN : SELECT 1 START WITH 1 = 1 CONNECT BY LEVEL <= 1
OUT: SELECT 1

WHERE survives (SELECT 1 WHERE 1 = 1 renders correctly), which shows the asymmetry.

Software Information:

  • JSqlParser 5.4-SNAPSHOT, master ad69ecc
  • JDK 17
  • any RDBMS (renderer-level, dialect independent)

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