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 15:22:12 |
Message-ID: | 4A6DC624.8080609@free.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello again,
Le 27/07/09 16:48, Jamie Lawrence-Jenner a écrit :
> Hi There
>
> Our update statements are as follows
>
> Update table set col1=x,col2=y where pkid=1;
> Update table set col1=x,col2=y where pkid=2;
> Update table set col1=x,col2=y where pkid=3;
>
> Very simple and straight forward. Sometimes there could be as many as 50
> update statements to process.
>
> Many thanks
>
> Jamie
> [...]
> Improvements on the merging UPDATE statements may thence be advised if
> some pieces of original statements could be given--without compromising
> confidential data.
>
Thanks for the examples.
Comparison between "explain analyze" outputs from the two ways (multiple
statements vs. one statement) should help choosing the faster.
For the one-statement schema, the rewritten query could be:
UPDATE yTable SET col1=x, col2=y WHERE pkID IN (1, 2, 3);
Lists of pkID would rather be expressed in terms of enumeration when in
WHERE clause. In a more general situation, I would recommand to
determine pkIDs list before building UPDATE statement(s) if possible.
This hint would surely save runtime.
With regards.
--
nha / Lyon / France.
From | Date | Subject | |
---|---|---|---|
Next Message | Saleem EDAH-TALLY | 2009-07-27 15:22:53 | Run procedure at startup |
Previous Message | Alexey Klyukin | 2009-07-27 14:54:07 | Calculating the difference between timetz values |