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

From: Jon Nelson <jnelson+pgsql(at)jamponi(dot)net>
To: 邓尧 <torshie(at)gmail(dot)com>
Cc: pgsql <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-09 01:53:59
Message-ID: CAKuK5J3wJ4-nTiJPqKfcMrCUnAxc_-1OyADovFQ3mw56maJZ1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Jan 8, 2012 at 7:13 PM, 邓尧 <torshie(at)gmail(dot)com> wrote:
> I have enabled the autocommit feature of psycopg2, and removed all the
> transactions in source code, also changed the sql statement to the
> following:
>
> insert into ACCOUNT(HOME)
>     select "v1" as HOME
>     where not exists (select 1 from ACCOUNT where HOME = "v1")
>
> Surprisingly, I still got the unique constraint violation error, but much
> fewer than before ( only 3 during the last 3 days).
> Any suggestions? Could it be a bug in psycopg2 or postgresql?

Presumably, you need to add a distinct.
insert into ... select DISTINCT .... where not exists.

--
Jon

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ondrej Ivanič 2012-01-09 01:54:51 Re: Time to move table to new tablespace
Previous Message Oliver Jowett 2012-01-09 01:32:39 Re: Binary Large Objects (LOB/BLOB) in Hibernate and JDBC: Unresolved issues