X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 478D23A1D8E for ; Mon, 22 Nov 2004 23:17:39 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21478-03 for ; Mon, 22 Nov 2004 23:17:22 +0000 (GMT) Received: from boutiquenumerique.com (boutiquenumerique.com [82.67.9.10]) by svr1.postgresql.org (Postfix) with ESMTP id AE79C3A22F0 for ; Mon, 22 Nov 2004 23:17:24 +0000 (GMT) Received: (qmail 19017 invoked from network); 23 Nov 2004 00:17:50 +0100 Received: from unknown (HELO musicbox) (boutiquenumerique-lists@192.168.0.2) by boutiquenumerique.com with SMTP; 23 Nov 2004 00:17:50 +0100 Date: Tue, 23 Nov 2004 00:19:17 +0100 To: "Richard Rowell" , pgsql-sql@postgresql.org Subject: Re: Recursive SETOF function References: <1101136693.18148.66.camel@richard> <1101151552.18145.86.camel@richard> From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: In-Reply-To: <1101151552.18145.86.camel@richard> User-Agent: Opera M2/7.54 (Linux, build 751) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200411/238 X-Sequence-Number: 19557 > SELECT INTO cid count(*) FROM providers WHERE uid =child_provider; Hey, hey. Better : SELECT blablah FROM providers WHERE uid = child_provider LIMIT 1; IF NOT FOUND THEN exit with error ELSE do your stuff Why scan more than 1 row when you just need existence ? Or : SELECT INTO cid parent_id FROM providers WHERE uid=cid; WHILE FOUND RETURN NEXT cid; SELECT INTO cid parent_id FROM providers WHERE uid=cid; END; Not sure about the While syntax but you get the idea.