Re: Replaceing records

From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
To: PgSQL General ML <pgsql-general(at)postgresql(dot)org>
Subject: Re: Replaceing records
Date: 2003-09-04 09:24:26
Message-ID: 1062667466.17057.11.camel@haggis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2003-09-04 at 03:00, Alex wrote:
> Hi,
> MySQL has a nice feature that allows to call a replace rather insert
> which will attempt to insert if record not present and replace if it does.
>
> Is there any similar feature ?
>
> Currently I run a select prior to any insert and then update or insert
> depending on the result of the select. The problem here is that I just
> doubled the queries. Doing so on a table with 5Mio rows and on 100k
> inserts will take time and I would like to have an efficient way of
> doing it.

What if you try do the INSERT, and if it returns with a "key exists"
error, do the UPDATE?

Will the SELECT really slow things down that much, since the record
will be in buffers after you touch it the 1st time?

--
-----------------------------------------------------------------
Ron Johnson, Jr. ron(dot)l(dot)johnson(at)cox(dot)net
Jefferson, LA USA

"All machines, no matter how complex, are considered to be based
on 6 simple elements: the lever, the pulley, the wheel and axle,
the screw, the wedge and the inclined plane."
Marilyn Vos Savant

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Paul Thomas 2003-09-04 09:59:33 Re: Tomcat Connection Pool?
Previous Message E. Zorn (RDG-rational) postsql 2003-09-04 09:12:55 WHERE boolean = true -> failure