X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id D8C67D1D8B4; Fri, 12 Dec 2003 21:21:33 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 96138-08; Fri, 12 Dec 2003 17:21:04 -0400 (AST) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id 86224D1D903; Fri, 12 Dec 2003 17:21:01 -0400 (AST) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.10/8.12.10) with ESMTP id hBCLKU8q012543; Fri, 12 Dec 2003 14:20:34 -0700 (MST) Date: Fri, 12 Dec 2003 14:02:35 -0700 (MST) From: "scott.marlowe" To: "Marc G. Fournier" Cc: Subject: Re: Skip dups on INSERT instead of generating an error ... In-Reply-To: <20031212165007.L81928@ganymede.hub.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IHS-MailScanner: Found to be clean X-IHS-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/95 X-Sequence-Number: 16261 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? I thought unions, by definition, couldn't create dups, unless you used the all keyword... OR do you just mean that you have dup pks, not the whole row?