Re: but i _really can't_ insert a duplicate key! - Mailing list pgsql-hackers

From Alfred Perlstein
Subject Re: but i _really can't_ insert a duplicate key!
Date
Msg-id 20000528214929.S28594@fw.wintelcom.net
Whole thread Raw
In response to but i _really can't_ insert a duplicate key!  (Alfred Perlstein <bright@wintelcom.net>)
List pgsql-hackers
* Alfred Perlstein <bright@wintelcom.net> [000527 16:03] wrote:
> 
> How is that possible?  My only guess is that the rule is only being applied
> to the table _before_ the query, and if there actually are duplicate rows
> to be inserted the rule isn't catching them because the exists clause is
> only running on the snapshot of the table before the insert starts.
> 
> is there a workaround or is this a possible bug?

Ok, this was my fault, it seems the rule system takes a snapshot of the
table at the start of a insert from select op and my rule wasn't catching
the rows that were inserted during the insert.  (basically confirmed my
suspicions)

I found the duplicate row in my original table and once it was
removed the the inserts seem to work perfectly.

It would be nice to have an exception handler that could be executed
when an insert fails because of various reason, something like:

create rule update_instread_of_insert as on exception to mytable  where exception = violates_unique do update ....

This would reduce the amount of searching because the insert rule only
happens when there is an exception instead of forcing an extra lookup
before each insert.

Anyhow, I can always wish. :)

thanks,
-- 
-Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org]
"I have the heart of a child; I keep it in a jar on my desk."


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Probably already asked but
Next
From: "Hiroshi Inoue"
Date:
Subject: RE: Berkeley DB...