All you need is a function that traverses the tree upwards and returns the
root's id.
create or replace function get_root_name(dept text) returns text as $$
declare
parent text := '';
prev_parent text;
begin
while( parent is not null ) loop
prev_parent := parent;
sele
Hello,
I have a table in my database with multiple, independent linked lists. I would
like to have a query that returns an entire linked list given a node (the node
could be anywhere within the list).
I found on the web an example of how to use CTEs to do this:
http://wiki.postgresql.org/wiki