X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 477FB9FB2EA for ; Thu, 21 Sep 2006 04:46:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 29077-01 for ; Thu, 21 Sep 2006 04:46:15 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.tacotec.de (mail.tacotec.de [83.137.101.41]) by postgresql.org (Postfix) with ESMTP id 795199FB2E5 for ; Thu, 21 Sep 2006 04:46:13 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.tacotec.de (Postfix) with ESMTP id 561AC11D556; Thu, 21 Sep 2006 09:46:12 +0200 (CEST) Received: from mail.tacotec.de ([83.137.101.41]) by localhost (hera.tacotec.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 28158-05; Thu, 21 Sep 2006 09:46:12 +0200 (CEST) Received: from lunix.schabi.de (p549D1A66.dip0.t-ipconnect.de [84.157.26.102]) by mail.tacotec.de (Postfix) with ESMTP id 0A83C11D538; Thu, 21 Sep 2006 09:46:11 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by lunix.schabi.de (Postfix) with ESMTP id 091B421B2BE; Thu, 21 Sep 2006 09:46:12 +0200 (CEST) Message-ID: <45124343.1060005@logix-tt.com> Date: Thu, 21 Sep 2006 09:46:11 +0200 From: Markus Schaber Reply-To: PostgreSQL - SQL User-Agent: Thunderbird 1.5.0.5 (X11/20060812) MIME-Version: 1.0 To: TJ O'Donnell Cc: pgsql-sql@postgresql.org Subject: Re: unique rows References: <4512208C.9050607@acm.org> In-Reply-To: <4512208C.9050607@acm.org> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at mail.tacotec.de X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.897 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, RCVD_IN_SORBS_WEB, SPF_HELO_PASS X-Spam-Level: X-Archive-Number: 200609/149 X-Sequence-Number: 26360 Hi, TJ, TJ O'Donnell wrote: > So, is there a way (a constraint, a check?) that will simply > REJECT a duplicate when I insert the raw data directly into x > rather than FAILING on an error as it does > with the unique constraint above? Failing on an error is exactly the way PostgreSQL (and the SQL standard) uses to REJECT duplicates. :-) You seem to think about silently dropping the duplicates. That could be achieved with an BEFORE INSERT trigger, or with a rule on a view, as both can silently drop the inserted rule. The trigger body could even be in language SQL, along the lines of: SELECT CASE WHEN EXISTS (SELECT keycol FROM table WHERE table.keycol=NEW.keycol) THEN NULL ELSE NEW; Nevertheless, expect the insert performance to drop a little, due to the trigger overhead. The alternative approaches (SELECT'ing from the application, using a stored procedure that checks and then inserts the data, and using subtransactions to roll back the failing inserts) all seem worse (uglier and slower) to me, but don't hesitate to ask if you're interested. HTH, Markus