pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-admin@postgresql.org
Subject: Re: Is there a batch/bulk UPDATE syntax available?
Date: Thu, 03 Feb 2011 13:31:27 +0100
Message-ID: <iie76t$tmu$1@dough.gmane.org> (raw)
In-Reply-To: <005b01cbc399$e8d99fa0$ba8cdee0$@com>
References: <005b01cbc399$e8d99fa0$ba8cdee0$@com>

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.




view thread (5+ messages)  latest in thread

Message-ID: <iie76t$tmu$1@dough.gmane.org>
Permalink:  ../iie76t$tmu$1@dough.gmane.org/
Also on:    postgresql.org/message-id/iie76t$tmu$1@dough.gmane.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: spam_eater@gmx.net
  Subject: Re: Is there a batch/bulk UPDATE syntax available?
  In-Reply-To: <iie76t$tmu$1@dough.gmane.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox