Dynamic SELECT condition - Mailing list pgsql-sql

From Victor Yegorov
Subject Dynamic SELECT condition
Date
Msg-id 20030224175300.GC2841@pirmabanka.lv
Whole thread Raw
Responses Re: Dynamic SELECT condition
Re: Dynamic SELECT condition
List pgsql-sql
Hello.

I'd like to know, is it possible to use returned data set values as
condition at runtime?

Here comes the details.
I have one table which links objects of various types into trees. Say, it has
5 rows:
parent_id | child_id
-----------+----------1         | 21         | 33         | 43         | 54         | 6
Each parent_id and child_id are primary keys in some other tables (don't matter
which, with object details).

Say, I'd like to show user a tree for object_id = 3 on the web.

Is it possible to get the following result set with one SQL request:
parent_id | child_id
-----------+----------3         | 43         | 54         | 6
I mean, I know the id of a root object, it's 3. If I'll extract with
condition parent_id = 3, then I'll get only 2 rows. I'd like to have a
recursive result set - while there are records in the table for which
count(next_level_parent_id == this_level_child_id) > 0, select parent_id, child_id.

I hope you'll understand my problem.

Thanks in advance.

--
Victor Yegorov

pgsql-sql by date:

Previous
From: no.spam@address.com
Date:
Subject: Re: Denormalizing during select
Next
From: no.spam@address.com
Date:
Subject: Denormalizing during select