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
Unable to parse ORACLE LISTAGG-Function in combination with OVER-Clause #1652
Exception in thread "main" net.sf.jsqlparser.JSQLParserException: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "BY" "BY"
at line 10, column 88.
Was expecting one of:
")"
","
"BINARY"
"BIT"
"CHAR"
"CHARACTER"
"DOUBLE"
"INTERVAL"
"JSON"
"SET"
"SIGNED"
"UNSIGNED"
"XML"
<DT_ZONE>
<K_DATETIMELITERAL>
<K_DATE_LITERAL>
<S_IDENTIFIER>
<S_QUOTED_IDENTIFIER>
while parsing the following statement (reduced to the minimum with sample data included):
-- not parseable
WITH CTE_DUMMY_DATA(COL_TO_AGG, PART_COL) AS (
SELECT'Foo', 1FROM DUAL
UNIONSELECT'Bar', 2FROM DUAL
UNIONSELECT'Baz', 1FROM DUAL
)
SELECT
LISTAGG (d.COL_TO_AGG, ' / ') WITHIN GROUP (ORDER BYd.COL_TO_AGG) OVER (PARTITION BY d.PART_COL) AS MY_LISTAGG
FROM cte_dummy_data d;
within group and over are not supported at the same time. Why not use the order by for window functions? I am not quite sure if I understand the use of within group here. This should work:
WITH CTE_DUMMY_DATA(COL_TO_AGG, PART_COL) AS (
SELECT 'Foo', 1 FROM DUAL
UNION
SELECT 'Bar', 2 FROM DUAL
UNION
SELECT 'Baz', 1 FROM DUAL
)
SELECT
LISTAGG (d.COL_TO_AGG, ' / ') OVER (PARTITION BY d.PART_COL ORDER BY d.COL_TO_AGG) AS MY_LISTAGG
FROM cte_dummy_data d;
Thank you for your reply. Unfortunately your suggestion is not feasible. According to Oracle's documentation (https://docs.oracle.com/cd/E11882_01/server.112/e41084/functions089.htm#SQLRF30030) the WITHIN GROUP clause is not optional when using LISTAGG. The execution results in an ORA-02000 when the WITHING GROUP clause is omitted.
Activity
wumpz commentedon Oct 28, 2022
within groupandoverare not supported at the same time. Why not use theorder byfor window functions? I am not quite sure if I understand the use ofwithin grouphere. This should work:andghe commentedon Oct 29, 2022
Hi @wumpz
Thank you for your reply. Unfortunately your suggestion is not feasible. According to Oracle's documentation (https://docs.oracle.com/cd/E11882_01/server.112/e41084/functions089.htm#SQLRF30030) the WITHIN GROUP clause is not optional when using LISTAGG. The execution results in an ORA-02000 when the WITHING GROUP clause is omitted.
manticore-projects commentedon Oct 29, 2022
Greetings,
thank your for reporting.
I do use
LISTAGGon Oracle myself and thus will look into this issue soonest.wumpz commentedon Nov 2, 2022
@andghe unfortunately you are right: http://sqlfiddle.com/#!4/c6069c/4/0. Sorry I missed that.
feat: LISTAGG() with OVER() clause
Assorted fixes (#1666)