X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id A776B9FA61D for ; Fri, 21 Jul 2006 13:01:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 75644-05 for ; Fri, 21 Jul 2006 16:01:46 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id 6965A9FA25A for ; Fri, 21 Jul 2006 13:01:45 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 85452350E5; Fri, 21 Jul 2006 09:01:44 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 83572350E2; Fri, 21 Jul 2006 09:01:44 -0700 (PDT) Date: Fri, 21 Jul 2006 09:01:44 -0700 (PDT) From: Stephan Szabo To: Kevin Nikiforuk Cc: pgsql-sql@postgresql.org Subject: Re: Error when trying to use a FOR loop In-Reply-To: <6EA72AC41F81D242A38AAF505523A94D022DF4@kappa.acrodex.net> Message-ID: <20060721085524.R28101@megazone.bigpanda.com> References: <6EA72AC41F81D242A38AAF505523A94D022DF4@kappa.acrodex.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200607/279 X-Sequence-Number: 25853 On Fri, 21 Jul 2006, Kevin Nikiforuk wrote: > Many thanks to Stephan, Richard and George. When I was reading the documentation about FOR loops, I didn't realize that I was in the plpgsql section! > > CREATE OR REPLACE FUNCTION rgio() RETURNS integer as $$ > BEGIN > DECLARE lv RECORD; You'd want to put declare first (it goes before begin). > FOR lv IN SELECT DISTINCT rg FROM ldevrg LOOP > SELECT ldev FROM ldevrg WHERE ldevrg='$lv'; I think you'd want something like ldevrg=lv.rg. > END LOOP; What's the final intent for this since AFAICS this is just going to do busy work that throws away the results. If you wanted to see the results of each of these selects you have to do a bit more work.