X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 3D4F7D1CA77 for ; Sun, 11 Apr 2004 04:17:23 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 58847-09 for ; Sun, 11 Apr 2004 04:17:21 -0300 (ADT) Received: from wolverine.lercnetworks.com (sabertooth.lercnetworks.com [140.99.13.90]) by svr1.postgresql.org (Postfix) with ESMTP id 6BE4AD1B566 for ; Sun, 11 Apr 2004 04:17:19 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) (uid 510) by wolverine.lercnetworks.com with local; Sun, 11 Apr 2004 00:59:51 -0400 From: "Dennis" To: "postgres SQL" Subject: cursors and for loops? Date: Sun, 11 Apr 2004 00:59:50 -0400 Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/104 X-Sequence-Number: 17479 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 loop" and what "fetch next" or "fetch all" evaluates to. Dennis pg-user@calico-consulting.com