[GENERAL] Path to top of tree

2007-11-13 Thread Steve Crawford
Given a table which includes tree-type information consisting of an id and a parent_id, is there an already existing function that will return the path to the top of the tree for a given record? The connectby function from the contrib tablefuncs does what I want for a whole table, but I haven'

Re: [GENERAL] Path to top of tree

2007-11-13 Thread Merlin Moncure
On Nov 13, 2007 3:35 PM, Steve Crawford <[EMAIL PROTECTED]> wrote: > Given a table which includes tree-type information consisting of an id > and a parent_id, is there an already existing function that will return > the path to the top of the tree for a given record? > > The connectby function from

Re: [GENERAL] Path to top of tree

2007-11-15 Thread Merlin Moncure
On Nov 13, 2007 10:54 PM, Merlin Moncure <[EMAIL PROTECTED]> wrote: > maybe or maybe not, but here is one way to do it: > > create or replace function parent(foo) returns foo as > $$ > select parent(foo) from foo where id = ($1).parent_id > union all > select $1 >