pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Nikiforuk <Kevin.Nikiforuk@Acrodex.com>
To: pgsql-sql@postgresql.org
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> (raw)

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;
        FOR lv IN SELECT DISTINCT rg FROM ldevrg LOOP
                SELECT ldev FROM ldevrg WHERE ldevrg='$lv';
        END LOOP;
RETURN 1;
END;
$$ LANGUAGE plpgsql;

So I've made progress, but I'm running into the same thing.
 
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:               ^
 
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:                                                                                        ^
 
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=# 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





view thread (8+ messages)  latest in thread

Message-ID: <6EA72AC41F81D242A38AAF505523A94D022DF4@kappa.acrodex.net>
Permalink:  ../6EA72AC41F81D242A38AAF505523A94D022DF4@kappa.acrodex.net/
Also on:    postgresql.org/message-id/6EA72AC41F81D242A38AAF505523A94D022DF4@kappa.acrodex.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: Kevin.Nikiforuk@Acrodex.com
  Subject: Re: Error when trying to use a FOR loop
  In-Reply-To: <6EA72AC41F81D242A38AAF505523A94D022DF4@kappa.acrodex.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox