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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-hackers by date

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