Reputation: 780
So I have a table called contains
that has the attributes parent
and child
I want to select all the childs and nested childs of a certain parent. I assume I have to use a recursive function but what would be the best way to go about that in postgresql?
I am currently finding childs using SELECT child FROM contains WHERE parent="name"
Upvotes: 0
Views: 1240
Reputation: 4350
You have to find all nested child. So you should use some recursive Query.
In PostgreSQL you can use Recursive Query to find all nested child.
the best examples that are exactly similar to your problem:
1- USING RECURSIVE COMMON TABLE EXPRESSIONS TO REPRESENT TREE STRUCTURES
2- Recursive WITH Query Evaluation In PostgreSQL – Explained
Upvotes: 1