X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 082D69DCBF0 for ; Tue, 28 Mar 2006 05:59:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78968-06 for ; Tue, 28 Mar 2006 05:59:29 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 47B529DCBBF for ; Tue, 28 Mar 2006 05:59:22 -0400 (AST) Received: from smtpq1.groni1.gr.home.nl (smtpq1.groni1.gr.home.nl [213.51.130.200]) by svr4.postgresql.org (Postfix) with ESMTP id 117755AF881 for ; Tue, 28 Mar 2006 09:59:25 +0000 (GMT) Received: from [213.51.130.190] (port=52339 helo=smtp1.groni1.gr.home.nl) by smtpq1.groni1.gr.home.nl with esmtp (Exim 4.30) id 1FOAyt-0006pw-Cg; Tue, 28 Mar 2006 11:59:19 +0200 Received: from cc503261-a.eelde1.dr.home.nl ([212.204.130.36]:51860 helo=[192.168.1.4]) by smtp1.groni1.gr.home.nl with esmtp (Exim 4.30) id 1FOAyr-0004XY-3d; Tue, 28 Mar 2006 11:59:17 +0200 Message-ID: <442908F1.5000802@gmail.com> Date: Tue, 28 Mar 2006 11:59:13 +0200 From: Wiebe Cazemier User-Agent: Mozilla Thunderbird 1.0.7 (X11/20060225) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Maciej Piekielniak Cc: pgsql-sql@postgresql.org Subject: Re: cursor and for update References: <1466365196.20060328013531@isb.com.pl> <4428866C.4000404@gmail.com> <1265912543.20060328111303@isb.com.pl> In-Reply-To: <1265912543.20060328111303@isb.com.pl> X-Enigmail-Version: 0.93.0.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig2CC3A1BF49ED63873111911C" X-AtHome-MailScanner-Information: Please contact support@home.nl for more information X-AtHome-MailScanner: Found to be clean X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200603/444 X-Sequence-Number: 24790 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig2CC3A1BF49ED63873111911C Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 03/28/06 11:13, Maciej Piekielniak wrote: >create or replace function uporzadkuj_reguly(text,text) RETURNS VOID AS >' >DECLARE > licznik integer:=1; > > reguly CURSOR FOR SELECT * from firewall ORDER BY id_firewall WHERE > tabela=$1 and lancuch=$2 for UPDATE; >BEGIN > for i in reguly LOOP > UPDATE firewall SET id_firewall=licznik WHERE CURRENT OF reguly; > licznik:=licznik+1; > END LOOP; > > return; >END;' >LANGUAGE 'plpgsql'; > Looping in postgres goes differently, at least, it does in version 8. I use loops like this (there are more ways, but I think what you're doing is wrong): FOR row IN (query) LOOP END LOOP; Where "row" is a variable of type RECORD. I'm not sure how this works with CURSOR, or if postgres 7.4 has different loop constructs, but you might want to look into that, in the documentation. It has a section on loops for plpgsql. --------------enig2CC3A1BF49ED63873111911C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFEKQj0MHkUjYo9d9ARAoEAAJ9sFhLCdY7K34W3fobIQL1UHR+rgACfZEhv MKr+/RDx/sHcreZxJFcnoC8= =rVsp -----END PGP SIGNATURE----- --------------enig2CC3A1BF49ED63873111911C--