X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4E191475F00 for ; Mon, 24 Feb 2003 13:21:42 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 28721-02 for ; Mon, 24 Feb 2003 13:21:31 -0500 (EST) Received: from shield.pirmabanka.lv (unknown [195.114.57.4]) by postgresql.org (Postfix) with ESMTP id E1EA5475F37 for ; Mon, 24 Feb 2003 12:52:43 -0500 (EST) Received: from wall2.pirmabanka.lv (wall2-pub.pirmabanka.lv [195.114.57.14]) by shield.pirmabanka.lv (8.9.3/8.9.3) with SMTP id TAA30319 for ; Mon, 24 Feb 2003 19:52:48 +0200 Received: from share.pirmabanka.lv ([10.0.0.10]) by wall2.pirmabanka.lv; Mon, 24 Feb 2003 19:52:48 +0200 (EET) Received: from pc311x1.pirmabanka.lv (IDENT:root@localhost.localdomain [127.0.0.1]) by pirmabanka.lv (8.11.5/8.11.5) with SMTP id h1OHqlZ16242 for ; Mon, 24 Feb 2003 19:52:47 +0200 Received: (qmail 2947 invoked by uid 100); 24 Feb 2003 17:53:00 -0000 Date: Mon, 24 Feb 2003 19:53:00 +0200 From: "Victor Yegorov" To: pgsql-sql@postgresql.org Subject: Dynamic SELECT condition Message-ID: <20030224175300.GC2841@pirmabanka.lv> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="RnlQjJ0d97Da+TV1" Content-Disposition: inline User-Agent: Mutt/1.4i X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/31 X-Sequence-Number: 12071 --RnlQjJ0d97Da+TV1 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 h= as 5 rows: parent_id | child_id -----------+---------- 1 | 2 1 | 3 3 | 4 3 | 5 4 | 6 =20 Each parent_id and child_id are primary keys in some other tables (don't ma= tter which, with object details). Say, I'd like to show user a tree for object_id =3D 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 =20 I mean, I know the id of a root object, it's 3. If I'll extract with condition parent_id =3D 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 =3D=3D this_level_child_id) > 0, select parent_i= d, child_id. I hope you'll understand my problem. Thanks in advance. -- Victor Yegorov --RnlQjJ0d97Da+TV1 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+Wlv82RKGLEykUDYRAisqAKC8uzJNjZhgrtsYVUgD3F4XT6g7+gCfZX2S 5a+ExLRvBhHvvewUz32+49k= =OBsH -----END PGP SIGNATURE----- --RnlQjJ0d97Da+TV1--