From: Victor Yegorov <viy@pirmabanka.lv>
To: pgsql-sql@postgresql.org
Subject: Dynamic SELECT condition
Date: Mon, 24 Feb 2003 19:53:00 +0200
Message-ID: <20030224175300.GC2841@pirmabanka.lv> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: viy@pirmabanka.lv
Subject: Re: Dynamic SELECT condition
In-Reply-To: <20030224175300.GC2841@pirmabanka.lv>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox