Skip to content

[Bug] When executing a recursive query (WITH RECURSIVE) in Apache Doris, the SQL fails to parse and throws a syntax error. #64968

Description

@babijisa

Search before asking

  • I had searched in the issues and found no similar issues.

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

  1. 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');
  2. Insert Data
    INSERT INTO tree VALUES
    (0, NULL, 'ROOT'),
    (1, 0, 'Child_1'),
    (2, 0, 'Child_2'),
    (3, 1, 'Child_1_1');
  3. 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?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions