Search Postgresql Archives

Re: Implementing replace function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux