Received: from zebra.siol.net (zebra.siol.net [193.189.160.16]) by postgresql.org (Postfix) with ESMTP id 576DC475476 for ; Sat, 30 Mar 2002 17:37:21 -0500 (EST) Received: from NELI ([193.77.252.187]) by zebra.siol.net (InterMail vK.4.03.04.00 201-232-130 license 5ac1ec526f2360901e54ffce7671dc4c) with ESMTP id <20020330223627.BJKB6894.zebra@NELI> for ; Sat, 30 Mar 2002 23:36:27 +0100 Date: Sat, 30 Mar 2002 23:37:15 +0100 From: Uros Gruber X-Mailer: The Bat! (v1.60) Reply-To: Uros Gruber Organization: Slovenska Internet Revija X-Priority: 3 (Normal) Message-ID: <93652058190.20020330233715@sir-mag.com> To: pgsql-general@postgresql.org Subject: Recursion in plpgsql MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200203/1355 X-Sequence-Number: 22713 Hi! i have one table with categories. And columns important for this to work. ID_CATEGORY and ID_PARENT. Now i want to do "HERE-YOU-ARE" navigation. First here is my PHP code for this. function catPath( $cat, $file ) { static $p; $path = $p; $strSQL = "SELECT Name,Parent FROM category WHERE IDCategory='$cat'"; $objDB->query( $strSQL ); $objDB->next_record(); $parent = $objDB->f( "Parent" ); $name = $objDB->f( "Name" ); $intProdCount = countProd( $cat ); if ( strlen( $parent ) > 0 ) { if ( $intProdCount > 0 ) { $p = "$name"; } else { $p = $name; } $p .= " $path"; catPath( $parent, $file ); } return $p; } This code is OK, but if i'm deeper in the tree code is slower and there is more sql queries. So i wan't to do this on sql server with plpgsql. I have 2 questions: How can i tell function to call herself like up in PHP example. And then is it possible to put data in some kind temporary table and when it finish doing recursion i will get data from that table and then use it in PHP. Is there anyone who can know how to solve this or maybe have better idea or maybe it not worth to worry about this because it's fast enough. -- bye Uros mailto:uros@sir-mag.com