Skip to content

Conversation

KKould
Copy link
Member

@KKould KKould commented Mar 10, 2025

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

CREATE OR REPLACE TABLE some_table (
	id INTEGER NOT NULL,
	"data" VARCHAR(50),
	parent_id INTEGER
);

INSERT INTO some_table (id, "data", parent_id) VALUES  (1, 'd1', NULL),(2, 'd2', 1),(3, 'd3', 1),(4, 'd4', 3),(5, 'd5', 3);

WITH RECURSIVE some_cte(id, "data", parent_id) AS
(SELECT some_table.id AS id, some_table."data" AS "data", some_table.parent_id AS parent_id
FROM some_table
WHERE some_table."data" IN ('d2', 'd3', 'd4') UNION ALL SELECT some_table_1.id AS id, some_table_1."data" AS "data", some_table_1.parent_id AS parent_id
FROM some_table AS some_table_1, some_cte AS c1
WHERE some_table_1.id = c1.parent_id)
 SELECT some_cte."data"
FROM some_cte
WHERE some_cte."data" != 'd2';
----
d1
d1
d1
d3
d3
d4

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Mar 10, 2025
@b41sh b41sh self-requested a review March 10, 2025 08:10
@b41sh b41sh changed the title fix: the output columns of cte related columns lack the columns requi… fix: the output columns of cte related columns lack the columns required by cte itself Mar 13, 2025
@b41sh b41sh merged commit b02aa15 into databendlabs:main Mar 14, 2025
76 checks passed
loloxwg pushed a commit to loloxwg/databend that referenced this pull request Apr 3, 2025
…red by cte itself (databendlabs#17576)

* fix: the output columns of cte related columns lack the columns required by cte itself

Signed-off-by: Kould <[email protected]>

* fix: the output columns of cte related columns lack the columns required by cte itself

Signed-off-by: Kould <[email protected]>

* chore: codefmt

Signed-off-by: Kould <[email protected]>

---------

Signed-off-by: Kould <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-bugfix this PR patches a bug in codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Recursive CTE error
3 participants