Re: Is there a batch/bulk UPDATE syntax available? - Mailing list pgsql-admin

From Thomas Kellerer
Subject Re: Is there a batch/bulk UPDATE syntax available?
Date
Msg-id iie76t$tmu$1@dough.gmane.org
Whole thread Raw
In response to Is there a batch/bulk UPDATE syntax available?  ("Gnanakumar" <gnanam@zoniac.com>)
List pgsql-admin
Gnanakumar, 03.02.2011 13:00:
> Is there a batch/bulk UPDATE query syntax available in PostgreSQL, similar
> to multirow VALUES syntax available for INSERT?
>
> INSERT Multirow VALUES syntax example:
> INSERT INTO films (code, title, did, date_prod, kind) VALUES
>      ('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy'),
>      ('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy');
>
> There is a situation in my application, where I am performing lots and lots
> of updates on individual rows. I am trying to figure out how to make the
> updates faster.
>
> Any other ideas/ways to make updates faster are highly appreciated.
>
> Regards,
> Gnanam
>
>
Maybe this pattern would work for you:

UPDATE my_table
    SET the_column = CASE
                       WHEN some_id_column = 1 then 100
                       WHEN some_id_column = 2 then 200
                       WHEN some_id_column = 3 then 300
                       WHEN some_id_column = 4 then 400
                       WHEN some_id_column = 5 then 500
                     END
WHERE some_id_column IN (1,2,3,4,5)

But that get's pretty nasty if you have more than just those 5 rows.

pgsql-admin by date:

Previous
From: "Gnanakumar"
Date:
Subject: Is there a batch/bulk UPDATE syntax available?
Next
From: pasman pasmański
Date:
Subject: Re: Is there a batch/bulk UPDATE syntax available?