Re: Is there a batch/bulk UPDATE syntax available?

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Is there a batch/bulk UPDATE syntax available?
Date: 2011-02-03 12:31:27
Message-ID: iie76t$tmu$1@dough.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Smith, Andy V 2011-02-03 13:10:12 PostgreSQL 9.0
Previous Message Gnanakumar 2011-02-03 12:00:08 Is there a batch/bulk UPDATE syntax available?