Re: Implementing replace function - Mailing list pgsql-general

From Matthieu Huin
Subject Re: Implementing replace function
Date
Msg-id 4CCFDE02.3010708@wallix.com
Whole thread Raw
In response to Re: Implementing replace function  (Thomas Kellerer <spam_eater@gmx.net>)
Responses Re: Implementing replace function  (Martijn van Oosterhout <kleptog@svana.org>)
List 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
>
>


pgsql-general by date:

Previous
From: Andreas 'ads' Scherbaum
Date:
Subject: [ANNOUNCE] PostgreSQL@FOSDEM 2011 - Call for talks
Next
From: Tom Lane
Date:
Subject: Re: index in desc order