Re: looping through query to update column

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Jean-Christophe Roux" <jcxxr(at)yahoo(dot)com>
Cc: "Albe Laurenz" <all(at)adv(dot)magwien(dot)gv(dot)at>, pgsql-general(at)postgresql(dot)org
Subject: Re: looping through query to update column
Date: 2006-10-13 13:57:16
Message-ID: b42b73150610130657r5742b14fs2c861ff471ecc6d2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/13/06, Jean-Christophe Roux <jcxxr(at)yahoo(dot)com> wrote:
>
> Thanks for the "ctid" trick. The code below worked fine
> for rec in select * from fromemail_trades loop
> update fromemail_trades set recordid = row where ctid = rec.ctid;
> row := row -1;
> end loop;
> The first line is a little different from your's:
> FOR row IN SELECT ctid, * FROM table FOR UPDATE LOOP
>
> How important is it to specify ctid in the select and to add 'for update'?

it's not. also, without a where clause you are better off just locking
the table (lock table...). also, the above loop is better achieved
via a single query.

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew - Supernews 2006-10-13 13:59:17 Re: looping through query to update column
Previous Message Richard Huxton 2006-10-13 13:54:51 Re: Postgresql 6.13