From: | "Victor Yegorov" <viy(at)pirmabanka(dot)lv> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Dynamic SELECT condition |
Date: | 2003-02-24 17:53:00 |
Message-ID: | 20030224175300.GC2841@pirmabanka.lv |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 | 2
1 | 3
3 | 4
3 | 5
4 | 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 | 4
3 | 5
4 | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2003-02-24 18:22:02 | Re: syntax question |
Previous Message | no.spam | 2003-02-24 17:18:24 | Denormalizing during select |