Search before asking
Version
Release 4.1.1
What's Wrong?
When executing a recursive query (WITH RECURSIVE) in Apache Doris, the SQL fails to parse and throws a syntax error.
Error message:
SQL Error [1105] [HY000]: errCode = 2, detailMessage =
no viable alternative at input 'WITH RECURSIVE search_tree'(line 1, pos 91)
📋 Steps to Reproduce
- Create Table
CREATE TABLE tree
(
id INT,
parent_id INT,
data VARCHAR(100)
)
DUPLICATE KEY (id)
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES ('replication_num' = '1');
- Insert Data
INSERT INTO tree VALUES
(0, NULL, 'ROOT'),
(1, 0, 'Child_1'),
(2, 0, 'Child_2'),
(3, 1, 'Child_1_1');
- Execute Recursive Query
WITH RECURSIVE search_tree AS (
SELECT id, parent_id, data
FROM tree t
WHERE t.id = 0
UNION ALL
SELECT t.id, t.parent_id, t.data
FROM tree t, search_tree st
WHERE t.parent_id = st.id
)
SELECT * FROM search_tree ORDER BY id;
What You Expected?
The query should execute successfully and return the hierarchical data:
0 NULL ROOT
1 0 Child_1
2 0 Child_2
3 1 Child_1_1
How to Reproduce?
No response
Anything Else?
No response
Are you willing to submit PR?
Code of Conduct
Search before asking
Version
Release 4.1.1
What's Wrong?
When executing a recursive query (WITH RECURSIVE) in Apache Doris, the SQL fails to parse and throws a syntax error.
Error message:
SQL Error [1105] [HY000]: errCode = 2, detailMessage =
no viable alternative at input 'WITH RECURSIVE search_tree'(line 1, pos 91)
📋 Steps to Reproduce
CREATE TABLE tree
(
id INT,
parent_id INT,
data VARCHAR(100)
)
DUPLICATE KEY (id)
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES ('replication_num' = '1');
INSERT INTO tree VALUES
(0, NULL, 'ROOT'),
(1, 0, 'Child_1'),
(2, 0, 'Child_2'),
(3, 1, 'Child_1_1');
WITH RECURSIVE search_tree AS (
SELECT id, parent_id, data
FROM tree t
WHERE t.id = 0
UNION ALL
SELECT t.id, t.parent_id, t.data
FROM tree t, search_tree st
WHERE t.parent_id = st.id
)
SELECT * FROM search_tree ORDER BY id;
What You Expected?
The query should execute successfully and return the hierarchical data:
0 NULL ROOT
1 0 Child_1
2 0 Child_2
3 1 Child_1_1
How to Reproduce?
No response
Anything Else?
No response
Are you willing to submit PR?
Code of Conduct