Re: Duplicated entries are not ignored even if a "do instead nothing" rule is added.

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Alban Hertroys <haramrae(at)gmail(dot)com>
Cc: 邓尧 <torshie(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Duplicated entries are not ignored even if a "do instead nothing" rule is added.
Date: 2012-01-03 17:11:12
Message-ID: CAHyXU0ykCfSGGPp=NPxDsB+kSKRyYhZU2YT8qDz9H8+AKDro0g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jan 3, 2012 at 1:42 AM, Alban Hertroys <haramrae(at)gmail(dot)com> wrote:
> On 3 Jan 2012, at 5:20, 邓尧 wrote:
>
>> Hi,
>>
>> I'm new to pgsql, I need the do something like the "INSERT IGNORE" in mysql. After some searching I got a solution, which is adding a "do instead nothing" rule to the corresponding table, but it fails sometimes.
>
> Yeah, if a concurrent transaction tries to create the same record, one of the transactions is going to find that it already exists on transaction commit. An INSERT-rule is not going to protect you against that.

It will if you lock the table first in the same transaction...note
this will greatly hurt concurrency and you have to watch for
deadlocks.

INSERT...SELECT..WHERE is going to be vastly superior to a rule based
approach obviously.

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Hagen Finley 2012-01-03 17:58:51 Re: Adding German Character Set to PostgresSQL
Previous Message Roberto Sanchez 2012-01-03 16:58:55 Re: stop server