You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] JSqlParser 5.4: ParseException on recursive CTE selecting a NUMBER column #2880
JSqlParser 5.4 fails to parse the following WITH RECURSIVE query. The CTE selects issue columns from T_ISSUE, then uses UNION ALL and a self-reference to retrieve child rows.
The reported error is at a comma in the select list, immediately after the unqualified column name NUMBER. It expects a numeric or string literal at that point. This may indicate that NUMBER is being interpreted as part of an expression instead of a column identifier, but I have not confirmed the root cause.
SQL Example:
WITH RECURSIVE
cte_name AS (
SELECT
ID,
PARENT_ID,
NUMBER,
TITLE,
MODEL_TYPE_ID,
TYPE_CLASSIFY,
PRIORITY,
STATE,
DEMAND_CLASSIFY,
PROJECT_ID,
CREATED_USER,
CREATED_TIME
FROM
T_ISSUE
WHERE
ID IN ('xxx')
UNION ALLSELECTl.ID,
l.PARENT_ID,
l.NUMBER,
l.TITLE,
l.MODEL_TYPE_ID,
l.TYPE_CLASSIFY,
l.PRIORITY,
l.STATE,
l.DEMAND_CLASSIFY,
l.PROJECT_ID,
l.CREATED_USER,
l.CREATED_TIMEFROM
T_ISSUE l
JOIN cte_name r ONl.PARENT_ID=r.ID
)
SELECT*FROM
cte_name
Actual behavior:
Parsing fails with the following exception (line and column refer to the original input formatting):
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered: <K_COMMA> / ",", at line 7, column 25, in lexical state DEFAULT.
Was expecting one of these terminals within expansion starting at 11417:9:
<S_DOUBLE> (inside 11417:9) ...
<S_LONG> (inside 11417:9) ...
<S_CHAR_LITERAL> (inside 11417:9) ...
Expected behavior:
The query should parse successfully, treating NUMBER and l.NUMBER as column references in their respective select lists.
Reproduction:
Save the SQL above as query.sql and parse it with JSqlParser 5.4:
I reproduced this on 5.4. A minimal reproducer is SELECT NUMBER FROM T_ISSUE, so it is unrelated to the recursive CTE. The parser incorrectly treats NUMBER as the start of a typed literal and expects a numeric or string literal after it.
This was fixed in #2644. I tested your complete SQL against master at 7123d25a: it parses and round-trips successfully, with NUMBER in both SELECT branches represented as column references.
You can use a build from the current master branch, which includes the fix. If you need to stay on 5.4, qualifying the first unqualified NUMBER as T_ISSUE.NUMBER also works; I verified that the complete SQL parses with this change.
Activity
fudianchn commentedon Nov 2, 2026
I reproduced this on 5.4. A minimal reproducer is
SELECT NUMBER FROM T_ISSUE, so it is unrelated to the recursive CTE. The parser incorrectly treatsNUMBERas the start of a typed literal and expects a numeric or string literal after it.This was fixed in #2644. I tested your complete SQL against master at
7123d25a: it parses and round-trips successfully, withNUMBERin both SELECT branches represented as column references.You can use a build from the current master branch, which includes the fix. If you need to stay on 5.4, qualifying the first unqualified
NUMBERasT_ISSUE.NUMBERalso works; I verified that the complete SQL parses with this change.