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 B65C59DD548 for ; Mon, 27 Mar 2006 20:42:22 -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 10961-02 for ; Mon, 27 Mar 2006 20:42:25 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 8DD839DD556 for ; Mon, 27 Mar 2006 20:42:20 -0400 (AST) Received: from smtpq3.groni1.gr.home.nl (smtpq3.groni1.gr.home.nl [213.51.130.202]) by svr4.postgresql.org (Postfix) with ESMTP id AF00D5AF83D for ; Tue, 28 Mar 2006 00:42:24 +0000 (GMT) Received: from [213.51.130.190] (port=55671 helo=smtp1.groni1.gr.home.nl) by smtpq3.groni1.gr.home.nl with esmtp (Exim 4.30) id 1FO2Ht-0002CC-IJ; Tue, 28 Mar 2006 02:42:21 +0200 Received: from cc503261-a.eelde1.dr.home.nl ([212.204.130.36]:40158 helo=[192.168.1.4]) by smtp1.groni1.gr.home.nl with esmtp (Exim 4.30) id 1FO2HY-0002hr-Ro; Tue, 28 Mar 2006 02:42:00 +0200 Message-ID: <4428866C.4000404@gmail.com> Date: Tue, 28 Mar 2006 02:42:20 +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> In-Reply-To: <1466365196.20060328013531@isb.com.pl> X-Enigmail-Version: 0.93.0.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigED063E923962AE3544B3BC3D" 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/440 X-Sequence-Number: 24786 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigED063E923962AE3544B3BC3D Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 03/28/06 01:35, Maciej Piekielniak wrote: >Hello , > >I try to translate my old functions from oracle but don't understand what is wrong. > >create or replace function uporzadkuj_reguly(text,text) RETURNS integer AS >' >DECLARE > tabela ALIAS FOR $1; > lancuch ALIAS FOR $2; > ret integer:=0; > licznik integer:=1; > rekord firewall%ROWTYPE; > > reguly CURSOR FOR SELECT * from firewall ORDER BY id_firewall WHERE tabela=tabela and lancuch=lancuch for UPDATE; >BEGIN > for i in reguly LOOP > UPDATE firewall SET id_firewall=licznik WHERE CURRENT OF reguly; > licznik:=licznik+1; > END LOOP; > > return ret; >END;' >LANGUAGE 'plpgsql'; > > > Fist, what's the error you get? Second, what does "rekord" do? You don't seem to use it. Third, can you quote the language? I always say plpgsql without the quotes, but I'm not sure if using quotes is not allowed (and I'm too lazy to check :)). Also, why don't you have a "RETURNS VOID" function, which you can end with "RETURN;" But what you might be stuck on is that you have a column and variable with the same name. Try to give the variables "tabela" and "lancunch" different names. Lastly, if you use postgres 8, you can quote your function with $$ instead of ' (meaning ...$$ AS DECLARE BEGIN END;$$...), so that you won't get the ugly syntax highligting that most editors will give you when quoting with '. --------------enigED063E923962AE3544B3BC3D 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 iD8DBQFEKIZsMHkUjYo9d9ARApPiAJ9LECASHIH6YXa8gTPcYM+KOaPXNwCgh2xR WhwPsn9o0OvRHMt2J/Snk2Y= =OGl1 -----END PGP SIGNATURE----- --------------enigED063E923962AE3544B3BC3D--