Re: Postgres and multiple updates in one statement

From: nha <lyondif02(at)free(dot)fr>
To: Jamie Lawrence-Jenner <jamie(dot)jenner(at)autovhc(dot)co(dot)uk>
Cc: PgSQL-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Postgres and multiple updates in one statement
Date: 2009-07-27 13:34:54
Message-ID: 4A6DACFE.6030101@free.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

Le 27/07/09 15:07, Raymond O'Donnell a écrit :
> On 27/07/2009 09:10, Jamie Lawrence-Jenner wrote:
>
>> Apart from saving on the overhead of having to open up 5 separate
>> connections, what are the benefits to passing in multiple updates in one
>> statement?
>
> If you do them all within one transaction -
>
> begin;
> update....
> update...
> ...
> commit;
>
> - then you save on the overhead associated with beginning and committing
> a transaction for each update.
>

Next to the transaction way suggested by Raymond O'Donnell, I would add
that performance would depend on FROM and WHERE clauses specified in the
original UPDATE statements.

In the case of multiple UPDATE statements following a quite "similar"
schema (ie. similar FROM (optional) and WHERE clauses), it might be
clearer (for the source code) and faster (for the database engine) to
merge them in a single UPDATE statement. Otherwise (ie. UPDATE
statements with not so much FROM and/or WHERE clauses in common),
transaction 1-block statement as suggested by Raymond O'Donnell would
certainly be the more appropriate.

Improvements on the merging UPDATE statements may thence be advised if
some pieces of original statements could be given--without compromising
confidential data.

Regards.

--
nha / Lyon / France.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua Tolley 2009-07-27 13:37:55 Re: Postgres and multiple updates in one statement
Previous Message Scott Marlowe 2009-07-27 13:31:37 Re: Postgres and multiple updates in one statement