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 584B39DC9F1 for ; Tue, 28 Mar 2006 05:13:03 -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 50368-02 for ; Tue, 28 Mar 2006 05:13:03 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from isb.com.pl (isb.com.pl [212.160.150.140]) by postgresql.org (Postfix) with ESMTP id 89C729DC9B6 for ; Tue, 28 Mar 2006 05:13:00 -0400 (AST) Received: from 192.168.0.17 (sembrz [192.168.1.50]) by isb.com.pl (Postfix) with ESMTP id 5469C57842 for ; Tue, 28 Mar 2006 11:09:31 +0200 (CEST) Date: Tue, 28 Mar 2006 11:13:03 +0200 From: Maciej Piekielniak X-Mailer: The Bat! (v1.62r) Reply-To: Maciej Piekielniak X-Priority: 3 (Normal) Message-ID: <1265912543.20060328111303@isb.com.pl> To: pgsql-sql@postgresql.org Subject: Re: cursor and for update In-Reply-To: <4428866C.4000404@gmail.com> References: <1466365196.20060328013531@isb.com.pl> <4428866C.4000404@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.1 required=5 tests=[AWL=0.100] X-Spam-Score: 0.1 X-Spam-Level: X-Archive-Number: 200603/443 X-Sequence-Number: 24789 Hello Wiebe, Tuesday, March 28, 2006, 2:42:20 AM, you wrote: >> WC> Fist, what's the error you get? ERROR: missing ".." at end of SQL expression CONTEXT: compile of PL/pgSQL function "uporzadkuj_reguly" near line 7 WC> Second, what does "rekord" do? You don't seem to use it. Yes, i don't need it. WC> Third, can you quote the language? I always say plpgsql without the WC> quotes, but I'm not sure if using quotes is not allowed (and I'm too WC> lazy to check :)). WC> Also, why don't you have a "RETURNS VOID" function, which you can end WC> with "RETURN;" OK WC> But what you might be stuck on is that you have a column and variable WC> with the same name. Try to give the variables "tabela" and "lancunch" WC> different names. OK WC> Lastly, if you use postgres 8, you can quote your function with $$ WC> instead of ' (meaning ...$$ AS DECLARE BEGIN END;$$...), so that you WC> won't get the ugly syntax highligting that most editors will give you WC> when quoting with '. I have postgres 7.4 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'; -- Best regards, Maciej mailto:piechcio@isb.com.pl