Re: on duplicate key - Mailing list pgsql-general

From Scott Marlowe
Subject Re: on duplicate key
Date
Msg-id dcc563d10809251245x6eb63704o938631e317ff7e12@mail.gmail.com
Whole thread Raw
In response to on duplicate key  ("A B" <gentosaker@gmail.com>)
List pgsql-general
On Thu, Sep 25, 2008 at 10:25 AM, A B <gentosaker@gmail.com> wrote:
> Hello.
> I was just asked by a mysql-user  how do you do
>  insert ..... on duplicate key  update ....
> (or  however they have it in mysql) in postgresql, if you are going to
> Is it correct to assume that a function that is searching for the key
> and then choosing to insert or update depending on what it found, is
> about as fast as doing an insert within a begin- exception-end
> statement or are there some inherent speed differences?

none really.  They're both usually quite fast.

> What should I answer the mysql-user?

You should ask him what happens if you setup a benchmark on mysql and
postgresq that runs 500 of these queries in parallel thousands of
times, and halfway through pull the plug.

Oh wait, I forgot, he's running mysql, so he probably doesn't actually
care about data integrity.  :)  P.s. I'm mostly just kidding around,
but in all seriousness, he's putting the cart ahead of the horse here.

> By the way, is there any work done on getting this functionality? I
> must admit that it would be handy some times ;-)

I don't know, I find running an update followed by an insert if the
update returns 0 rows is pretty easy to do.  From external code or
your favorite pl/lang.

pgsql-general by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: ease of use sync
Next
From: Casey Allen Shobe
Date:
Subject: Re: Oracle and Postgresql