Re: [Q]updating multiple rows with Different values

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [Q]updating multiple rows with Different values
Date: 2008-11-23 09:05:33
Message-ID: 20081123090533.GA8166@tux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

V S P <toreason(at)fastmail(dot)fm> schrieb:

> Hello,
> searched documentation, FAQ and mailing list archives
> (mailing list archive search is volumous :-) )
>
> but could not find an answer:
>
> I would like to be able to update
> several rows to different values at the same time
>
> In oracle this used to be called Array update or
> 'collect' update or 'bulk' update -- but those
> keywords did not bring anything for Postgresql.

test=# create table foo (id int, val int);
CREATE TABLE
Zeit: 0,837 ms
test=*# insert into foo values (1,1);
INSERT 0 1
Zeit: 0,434 ms
test=*# insert into foo values (2,2);
INSERT 0 1
Zeit: 0,298 ms
test=*# update foo set val = case when id=1 then 10 when id=2 then 20
end;
UPDATE 2
Zeit: 0,424 ms
test=*# select * from foo;
id | val
----+-----
1 | 10
2 | 20
(2 Zeilen)

Is this okay for you?

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gerhard Heift 2008-11-23 09:11:56 Re: [Q]updating multiple rows with Different values
Previous Message Ciprian Dorin Craciun 2008-11-23 06:39:25 Re: Using Postgres to store high volume streams of sensor readings

Browse pgsql-hackers by date

  From Date Subject
Next Message Gerhard Heift 2008-11-23 09:11:56 Re: [Q]updating multiple rows with Different values
Previous Message Tom Lane 2008-11-23 04:03:01 Re: portability of "designated initializers"