From: | Andrew - Supernews <andrew+nonews(at)supernews(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: looping through query to update column |
Date: | 2006-10-13 13:59:17 |
Message-ID: | slrneiv6tl.27so.andrew+nonews@atlantis.supernews.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 2006-10-13, "Albe Laurenz" <all(at)adv(dot)magwien(dot)gv(dot)at> wrote:
> You lock the table (with LOCK) or the row you're working on
> (with SELECT FOR UPDATE) so that nobody else can change it while
> you are working on it.
>
> You need something like ctid if your table has the fundamental flaw
> of lacking a primary key.
Looping over rows unnecessarily is a mistake.
You can add a SERIAL column to a table using ALTER TABLE, which will
automatically number the existing rows; this is a better way to fix a
lack of a primary key than messing around with ctids.
For a one-off update, use a temporary sequence:
create temporary sequence foo;
update table set recordid = nextval('foo');
--
Andrew, Supernews
http://www.supernews.com - individual and corporate NNTP services
From | Date | Subject | |
---|---|---|---|
Next Message | Martijn van Oosterhout | 2006-10-13 14:12:56 | Re: UTF-8 |
Previous Message | Merlin Moncure | 2006-10-13 13:57:16 | Re: looping through query to update column |