cursors and for loops? - Mailing list pgsql-sql

From Dennis
Subject cursors and for loops?
Date
Msg-id courier.4078D0C7.00000C8F@wolverine.lercnetworks.com
Whole thread Raw
Responses Re: cursors and for loops?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
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 '
DECLAREparId    ALIAS FOR $1;      dennis varchar;      tmp_xvalues RECORD; 
attrVals        CURSOR (thePar varchar)    IS select '' '' || name ||''="''|| value ||''"'' as rval        from attbl
whereidcol = 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


pgsql-sql by date:

Previous
From: Bret Hughes
Date:
Subject: trigger/for key help
Next
From: Stephan Szabo
Date:
Subject: Re: trigger/for key help