Recursive function w/ hierarchical data

From: Fran Fabrizio <ffabrizio(at)mmrd(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Recursive function w/ hierarchical data
Date: 2001-10-24 21:28:44
Message-ID: 3BD7328C.B6D0FD44@mmrd.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-general by date

  From Date Subject
Next Message Doug McNaught 2001-10-24 21:30:15 Re: Function won't compile
Previous Message Johnny Jørgensen 2001-10-24 21:21:33 Re: Can not input large text data