Recursive function w/ hierarchical data - Mailing list pgsql-general

From Fran Fabrizio
Subject Recursive function w/ hierarchical data
Date
Msg-id 3BD7328C.B6D0FD44@mmrd.com
Whole thread Raw
List pgsql-general
Hello,

I have a table like this:

id       parent_id
-----------------------
1        null
2        1
3        1
4        2
5        2
6        2
7        3
etc....

and I'd like to write a function get_children(int) that returned the set
of children for the id passed in as $1.

This will be a recursive function, and I did find a recent newsgroup
post (I think originally from the HACKERS
list) about how to implement recursive SQL functions in Postgres, but
I'm not sure how to go about building the
result set as I go.  Does it involve the creation of a temporary table
to hold the results?

Thanks,
Fran


pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Listing users
Next
From: "Aasmund Midttun Godal"
Date:
Subject: Re: Function won't compile