X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E81819FA42F for ; Fri, 21 Jul 2006 12:26:36 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 67369-07 for ; Fri, 21 Jul 2006 12:26:24 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from pluto.acrodex.com (pluto.acrodex.com [139.142.184.4]) by postgresql.org (Postfix) with ESMTP id C68069FA3B3 for ; Fri, 21 Jul 2006 12:26:23 -0300 (ADT) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: Error when trying to use a FOR loop Date: Fri, 21 Jul 2006 09:26:21 -0600 Message-ID: <6EA72AC41F81D242A38AAF505523A94D022DF4@kappa.acrodex.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Error when trying to use a FOR loop Thread-Index: AcasAu4kigmP+DfxTwS5E1tAkwfPzgA1hEWE From: "Kevin Nikiforuk" To: X-imss-version: 2.041 X-imss-result: Passed X-imss-scores: Clean:43.87967 C:2 M:3 S:5 R:5 X-imss-settings: Baseline:2 C:1 M:1 S:1 R:1 (0.1500 0.1500) 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/275 X-Sequence-Number: 25849 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! =20 CREATE OR REPLACE FUNCTION rgio() RETURNS integer as $$ BEGIN DECLARE lv RECORD; FOR lv IN SELECT DISTINCT rg FROM ldevrg LOOP SELECT ldev FROM ldevrg WHERE ldevrg=3D'$lv'; END LOOP; RETURN 1; END; $$ LANGUAGE plpgsql; So I've made progress, but I'm running into the same thing. =20 psql:rgio.sql:16: ERROR: syntax error at or near "FOR" at character 86 psql:rgio.sql:16: LINE 6: FOR lv IN SELECT DISTINCT rg FROM ldevrg LOOP psql:rgio.sql:16: ^ =20 If I comment out the DECLARE statement above, I get the following: psql:rgio.sql:16: ERROR: loop variable of loop over rows must be record = or row variable at or near "LOOP" at character 129 psql:rgio.sql:16: LINE 6: FOR lv IN SELECT DISTINCT rg FROM ldevrg LOOP psql:rgio.sql:16: = ^ =20 Ideas? ________________________________ From: pgsql-sql-owner@postgresql.org on behalf of Kevin Nikiforuk Sent: Thu 7/20/2006 7:46 AM To: pgsql-sql@postgresql.org Subject: [SQL] Error when trying to use a FOR loop Sorry if this is in the archives, but I've done a search and couldn't = find anything relevant. I'm running HP's precompiled version of 8.1.3.1 = as part of their Internet Express offering, and I can't seem to run a = for loop. Here's what I'm seeing: xp512-0715-0716=3D# FOR LV in 1..10 LOOP xp512-0715-0716-# select * from ldevrg; ERROR: syntax error at or near "FOR" at character 1 LINE 1: FOR LV in 1..10 LOOP ^ I'm still pretty new to postgres, but based on the documentation I'm not = picking up what I'm doing wrong. Help much appreciated. Thanks, Kevin ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq