Re: Automatic rollback on error, duplicate key?

Gerhard Häring <[email protected]>
Newsgroups gmane.comp.python.db.pypgsql.user
Organization People's Front of Judea
Message-ID <[email protected]>
* Bob Kimble <bob-ECzipMoozfpWk0Htik3J/[email protected]> [2002-11-12 00:21 -0500]:
> Perhaps you could use a rule to achieve what you want. You could create a 
> clone of table 2 augmented with a rule that checks to see if the row you just 
> inserted into the clone exists already in table 2. [...]

Well, no need for a separate table:

CREATE RULE RUL_MYTABLE_INS AS 
    ON INSERT TO MYTABLE
        WHERE NEW.MYUNIQUECOLUMN IN (
            SELECT MYUNIQUECOLUMN FROM MYTABLE)
DO INSTEAD NOTHING;

-- Gerhard


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.