Help pls with UPDATE

Started by goover 20 years ago3 messagesgeneral
Jump to latest
#1go
go@ugnn.ru

Hi, pgsql-general.

Tell me please, how to update a set of rows using order-
something like :

update my_table set counter1=nextval('my_seq') order by counter2 ;

--
Regards,
Igor mailto:go@ugnn.ru

#2Guy Rouillier
guyr@masergy.com
In reply to: go (#1)
Re: Help pls with UPDATE

go KEY802207 wrote:

Hi, pgsql-general.

Tell me please, how to update a set of rows using order-
something like :

update my_table set counter1=nextval('my_seq') order by counter2 ;

The way this is usually done is to issue a SELECT with an ORDER BY
clause, then update the rows that are returned. Many DBMSs have a
SELECT FOR UPDATE and then UPDATE WHERE CURRENT OF CURSOR, but a quick
read of the documentation doesn't list such constructs for PostgreSQL,
so if not you'll need to use separate statements.

--
Guy Rouillier

#3Michael Glaesemann
grzm@seespotcode.net
In reply to: Guy Rouillier (#2)
Re: Help pls with UPDATE

On Nov 1, 2005, at 13:40 , Guy Rouillier wrote:

go KEY802207 wrote:

Hi, pgsql-general.

Tell me please, how to update a set of rows using order-
something like :

update my_table set counter1=nextval('my_seq') order by counter2 ;

The way this is usually done is to issue a SELECT with an ORDER BY
clause, then update the rows that are returned. Many DBMSs have a
SELECT FOR UPDATE and then UPDATE WHERE CURRENT OF CURSOR, but a quick
read of the documentation doesn't list such constructs for PostgreSQL,
so if not you'll need to use separate statements.

I don't know whether this does exactly what you need, but PostgreSQL
does have SELECT FOR UPDATE. Hopefully the docs will be able to
answer whether or not this will helpyou better than I can :)

http://www.postgresql.org/docs/8.0/interactive/sql-select.html#SQL-
FOR-UPDATE

Michael Glaesemann
grzm myrealbox com