From: | Wiebe Cazemier <halfgaar(at)gmail(dot)com> |
---|---|
To: | Maciej Piekielniak <piechcio(at)isb(dot)com(dot)pl> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: cursor and for update |
Date: | 2006-03-28 09:59:13 |
Message-ID: | 442908F1.5000802@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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.
From | Date | Subject | |
---|---|---|---|
Next Message | Fay Du | 2006-03-28 16:41:39 | Update question |
Previous Message | Maciej Piekielniak | 2006-03-28 09:13:03 | Re: cursor and for update |