Re: [Q]updating multiple rows with Different values

From: Gerhard Heift <ml-postgresql-20081012-3518(at)gheift(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [Q]updating multiple rows with Different values
Date: 2008-11-23 09:11:56
Message-ID: 20081123091156.GA5804@toaster.kawo1.rwth-aachen.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Sat, Nov 22, 2008 at 10:04:48PM -0500, V S P wrote:
> 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.
>
> for example tbl_1 has two columns id and col1
>
>
> update tbl_1 set
> col1=3 where id=25,
> col1=5 where id=26

Something like this?

UPDATE tbl_1 SET col1 = t.col1 FROM (VALUES
(25, 3)
(26, 5)
) AS t(id, col1)
WHERE tbl_1.id = t.id;

> I am using PHP PDO (and hoping that if there is a mechanism
> within postgresql to do that PDO will support it as well).
>
> Thank you in advance,
> VSP

Regards,
Gerhard

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2008-11-23 11:20:41 Re: date stamp on update?
Previous Message Andreas Kretschmer 2008-11-23 09:05:33 Re: [Q]updating multiple rows with Different values

Browse pgsql-hackers by date

  From Date Subject
Next Message V S P 2008-11-23 15:43:37 Re: [Q]updating multiple rows with Different values
Previous Message Andreas Kretschmer 2008-11-23 09:05:33 Re: [Q]updating multiple rows with Different values