Skip site navigation (1) Skip section navigation (2)

Re: but i _really can't_ insert a duplicate key!

From: Alfred Perlstein <bright(at)wintelcom(dot)net>
To: pgsql-hackers(at)hub(dot)org
Subject: Re: but i _really can't_ insert a duplicate key!
Date: 2000-05-29 04:49:29
Message-ID: 20000528214929.S28594@fw.wintelcom.net (view raw or flat)
Thread:
Lists: pgsql-hackers
* Alfred Perlstein <bright(at)wintelcom(dot)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(at)wintelcom(dot)net|alfred(at)freebsd(dot)org]
"I have the heart of a child; I keep it in a jar on my desk."

In response to

pgsql-hackers by date

Next:From: Hiroshi InoueDate: 2000-05-29 04:51:42
Subject: RE: Berkeley DB...
Previous:From: Tom LaneDate: 2000-05-29 04:12:49
Subject: Re: Probably already asked but

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group