Re: Skip dups on INSERT instead of generating an error ...

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Skip dups on INSERT instead of generating an error ...
Date: 2003-12-12 21:03:10
Message-ID: Pine.LNX.4.33.0312121402470.18790-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, 12 Dec 2003, Marc G. Fournier wrote:

>
> I need to be able to run an INSERT INTO / SELECT FROM UNION which combines
> two tables into one ... *but* ... the INTO table has a primary key on the
> first column, so if the result of the UNION generates dups, by default, of
> course, it will generate errors ... what I'd like is to have it so that it
> just skips over those records.
>
> First thought would be to write a quite plpgsql function that would do a
> SELECT first, to see if the value already exists, and if not, then do the
> INSERT ... but am wondering if maybe there is a cleaner way that I'm not
> thinking of?

Crap, just read what you actually wrote. Hmmm. I'd guess a trigger on
the table might be able to do it, but performance is gonna suck.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tomasz Myrta 2003-12-12 21:33:36 Re: Skip dups on INSERT instead of generating an error ...
Previous Message scott.marlowe 2003-12-12 21:02:35 Re: Skip dups on INSERT instead of generating an error ...