Re: [Q]updating multiple rows with Different values - Mailing list pgsql-general

From Andreas Kretschmer
Subject Re: [Q]updating multiple rows with Different values
Date
Msg-id 20081123090533.GA8166@tux
Whole thread Raw
In response to [Q]updating multiple rows with Different values  ("V S P" <toreason@fastmail.fm>)
List pgsql-general
V S P <toreason@fastmail.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°

pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Postgres mail list traffic over time
Next
From: Gerhard Heift
Date:
Subject: Re: [Q]updating multiple rows with Different values