Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: CTE with WHERE clause does not work #17027

Closed
1 of 2 tasks
rad-pat opened this issue Dec 10, 2024 · 0 comments · Fixed by #17031
Closed
1 of 2 tasks

bug: CTE with WHERE clause does not work #17027

rad-pat opened this issue Dec 10, 2024 · 0 comments · Fixed by #17031
Assignees
Labels
C-bug Category: something isn't working

Comments

@rad-pat
Copy link

rad-pat commented Dec 10, 2024

Search before asking

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

Version

v1.2.670-nightly

What's Wrong?

Query table with recursive CTE and where clause, get wrong result.

How to Reproduce?

CREATE TABLE parent_child 
(
  parent VARCHAR(30),
  child VARCHAR(30)
);
INSERT INTO parent_child 
VALUES ('Org','Org'),('Org','Global'),('Global','North'),
('Global','South'),('Global','East'),('Global','West'),
('Global','Org detail'),('North','North East'),('North','North West');

WITH RECURSIVE tree_values
    (parent, child)
AS (
    
    SELECT parent, child
    FROM parent_child
    WHERE parent = child
        
    UNION ALL
    
    SELECT c.parent, c.child
    FROM parent_child c
    INNER JOIN tree_values p
    ON p.child = c.parent        
    WHERE c.parent != c.child
)
select parent, child from tree_values
where parent = 'Global'

Expect 5 rows, actually returns no rows. Remove where clause, works as expected

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
@rad-pat rad-pat added the C-bug Category: something isn't working label Dec 10, 2024
@xudong963 xudong963 self-assigned this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants