Path to top of tree - Mailing list pgsql-general

From Steve Crawford
Subject Path to top of tree
Date
Msg-id 473A0A8E.40102@pinpointresearch.com
Whole thread Raw
Responses Re: Path to top of tree  ("Merlin Moncure" <mmoncure@gmail.com>)
List pgsql-general
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't found a way to execute it in an efficient
way to get the information for a single record. A query in the form of
"select connectby(.....) where ..." will return the answer I want, but
it builds the tree on the whole table and then filters to get the record
I want which, for 5000 records, is taking about half a minute.

Before I start writing my own function, have I overlooked something
already available or some better way to invoke connectby?

Cheers,
Steve


pgsql-general by date:

Previous
From: "Charles Mortell"
Date:
Subject: Re: update record with two-column primary key
Next
From: "Morris Goldstein"
Date:
Subject: Impact of table scan on shared buffers