From: | Matthieu Huin <matthieu(dot)huin(at)wallix(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Implementing replace function |
Date: | 2010-11-02 09:46:42 |
Message-ID: | 4CCFDE02.3010708@wallix.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
If you expect your data to reach some kind of "critical size" at some
point ( ie updates will be more likely than inserts at that point ), you
can optimize your UPSERT code by trying to UPDATE before INSERTing.
Otherwise trying to INSERT first should decrease the average UPSERT
execution time in the long run, since you are less likely to hit the
exception and do some extra work on the table.
Anyway, glad to hear this is going to be accounted for in 9.1 . :)
Le 31/10/2010 11:07, Thomas Kellerer a écrit :
> Alexander Farber wrote on 31.10.2010 09:22:
>> Hello Postgres users,
>>
>> to mimic the MySQL-REPLACE statement I need
>> to try to UPDATE a record and if that fails - INSERT it.
>>
>
> There is actually an example of this in the PG manual ;)
>
> http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE
>
>
> Here is another solution based on triggers:
> http://database-programmer.blogspot.com/2009/06/approaches-to-upsert.html
>
> Regards
> Thomas
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | RP Khare | 2010-11-02 09:47:51 | Dealing with locking on batch updates. |
Previous Message | Szymon Guz | 2010-11-02 09:42:05 | Re: index in desc order |