pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Wiebe Cazemier <halfgaar@gmail.com>
To: Maciej Piekielniak <piechcio@isb.com.pl>
Cc: pgsql-sql@postgresql.org
Subject: Re: cursor and for update
Date: Tue, 28 Mar 2006 11:59:13 +0200
Message-ID: <442908F1.5000802@gmail.com> (raw)
In-Reply-To: <1265912543.20060328111303@isb.com.pl>
References: <1466365196.20060328013531@isb.com.pl>
	<4428866C.4000404@gmail.com>
	<1265912543.20060328111303@isb.com.pl>

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.

Attachments:

  signature.asc (application/pgp-signature, 257B) download

view thread (4+ messages)

Message-ID: <442908F1.5000802@gmail.com>
Permalink:  ../442908F1.5000802@gmail.com/
Also on:    postgresql.org/message-id/442908F1.5000802@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: halfgaar@gmail.com, piechcio@isb.com.pl
  Subject: Re: cursor and for update
  In-Reply-To: <442908F1.5000802@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox