Details
-
New Feature
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
3.1.0
Description
Examples
Here is an example for WITH RECURSIVE clause usage. Table "department" represents the structure of an organization as an adjacency list.
CREATE TABLE department ( id INTEGER PRIMARY KEY, -- department ID parent_department INTEGER REFERENCES department, -- upper department ID name TEXT -- department name ); INSERT INTO department (id, parent_department, "name") VALUES (0, NULL, 'ROOT'), (1, 0, 'A'), (2, 1, 'B'), (3, 2, 'C'), (4, 2, 'D'), (5, 0, 'E'), (6, 4, 'F'), (7, 5, 'G'); -- department structure represented here is as follows: -- -- ROOT-+->A-+->B-+->C -- | | -- | +->D-+->F -- +->E-+->G
To extract all departments under A, you can use the following recursive query:
WITH RECURSIVE subdepartment AS ( -- non-recursive term SELECT * FROM department WHERE name = 'A' UNION ALL -- recursive term SELECT d.* FROM department AS d JOIN subdepartment AS sd ON (d.parent_department = sd.id) ) SELECT * FROM subdepartment ORDER BY name;
More details:
Attachments
Issue Links
- blocks
-
SPARK-28453 Support recursive view syntax
-
- Resolved
-
-
SPARK-28731 Support limit on recursive queries
-
- Resolved
-
- is duplicated by
-
SPARK-42836 Support for recursive queries
-
- Resolved
-
- relates to
-
SPARK-33459 Commonly used Teradata extension syntax
-
- Open
-
- links to
(7 links to)