pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dennis <pg-user@calico-consulting.com>
To: postgres SQL <pgsql-sql@postgresql.org>
Subject: cursors and for loops?
Date: Sun, 11 Apr 2004 00:59:50 -0400
Message-ID: <courier.4078D0C7.00000C8F@wolverine.lercnetworks.com> (raw)

Hello, 

I am wondering if I can use a cursor in a for loop. I haven't been able to 
get it to work. I am just beginning plpgsql and I am struggling here. 

I am trying to do this: 


create or replace function ttest(varchar)
RETURNS varchar AS '
DECLARE
	parId	ALIAS FOR $1;
       dennis varchar;
       tmp_xvalues RECORD;
	 

	attrVals		CURSOR (thePar varchar)
		IS select '' '' || name ||''="''|| value ||''"'' as rval
			from attbl where idcol = thePar;
BEGIN
	 

	OPEN attrVals(parId); 

       for tmp_xvalues in fetch all from attrVals loop
           dennis := dennis || tmp_xvalues.rval;
       end loop; 

	
	return dennis;
END;
' language plpgsql; 

If I try to use this function like so: 

select ttest('blah') 

I get:
Error: ERROR:  syntax error at or near "all" at character 15 

I guess I am confused what I can put in "for var in <expression> loop" and 
what "fetch next" or "fetch all" evaluates to. 

Dennis
pg-user@calico-consulting.com



view thread (5+ messages)  latest in thread

Message-ID: <courier.4078D0C7.00000C8F@wolverine.lercnetworks.com>
Permalink:  ../courier.4078D0C7.00000C8F@wolverine.lercnetworks.com/
Also on:    postgresql.org/message-id/courier.4078D0C7.00000C8F@wolverine.lercnetworks.com

 · 

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: pg-user@calico-consulting.com
  Subject: Re: cursors and for loops?
  In-Reply-To: <courier.4078D0C7.00000C8F@wolverine.lercnetworks.com>

* 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