Search Postgresql Archives

Re: [Q]updating multiple rows with Different values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



V S P <toreason@xxxxxxxxxxx> 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°

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux