Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4EB4F632954 for ; Tue, 20 Apr 2010 04:24:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 98042-09 for ; Tue, 20 Apr 2010 07:24:31 +0000 (UTC) X-Greylist: delayed 00:22:02.429994 by SQLgrey-1.7.6 Received: from out.mail.amis.hr (out.mail.amis.hr [194.146.109.198]) by mail.postgresql.org (Postfix) with ESMTP id B3D3262E522 for ; Tue, 20 Apr 2010 04:24:30 -0300 (ADT) Received: from relay.srv.amis.hr (relay.srv.amis.hr [192.168.103.201]) by out.mail.amis.hr (Postfix) with ESMTP id 2F7E966874E; Tue, 20 Apr 2010 09:02:25 +0200 (CEST) Received: from pps.filterd (relay [127.0.0.1]) by relay.srv.amis.hr (8.14.3/8.14.3) with SMTP id o3K71oDC008383; Tue, 20 Apr 2010 09:02:25 +0200 Received: from in.mail.amis.hr (in1.mail.srv.amis.hr [192.168.103.31]) by relay.srv.amis.hr with ESMTP id n8pg20gn7-4; Tue, 20 Apr 2010 09:02:24 +0200 Received: from imap.amis.hr (imap.srv.amis.hr [192.168.103.37]) by in.mail.amis.hr (Postfix) with ESMTP id 6F4C6282; Tue, 20 Apr 2010 09:02:24 +0200 (CEST) Received: from [192.168.10.1] (cpe-188-129-74-112.dynamic.amis.hr [188.129.74.112]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by imap.amis.hr (Postfix) with ESMTP id BFB0DB00557; Tue, 20 Apr 2010 09:02:17 +0200 (CEST) Message-ID: <4BCD517D.8090107@megafon.hr> Date: Tue, 20 Apr 2010 09:02:21 +0200 From: Mario Splivalo User-Agent: Thunderbird 2.0.0.24 (X11/20100411) MIME-Version: 1.0 To: pgsql-sql@postgresql.org CC: Tom Lane , Jasen Betts Subject: Re: Re: CHECK constraints with plpgsql functions - check 'fires' BEFORE data modification? References: <4BCC272C.3020505@megafon.hr> <13340.1271686859@sss.pgh.pa.us> In-Reply-To: <13340.1271686859@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.5 tagged_above=-10 required=5 tests=BAYES_05=-0.5 X-Spam-Level: X-Archive-Number: 201004/62 X-Sequence-Number: 33989 Tom Lane wrote: > > I think what Mario is actually complaining about is that partial unique > indexes are not part of the SQL standard, and he wants a solution that > at least gives the illusion that it might be portable to some other > RDBMS in the future. Correct. As far as I can see there is no partial unique constraints defined within the standard, and there are check constraints, so... Although, especially after this: > Unfortunately, an illusion is all it would be. Even presuming that the > other DBMS lets you run plpgsql-equivalent functions in CHECK > constraints, the whole approach is broken by concurrency considerations. > If you have two transactions simultaneously inserting rows that would be > valid given the prior state of the table, but it's *not* valid for them > both to be present, then a CHECK or trigger-based constraint is going to > fail, because neither transaction will see the other's uncommitted row. > At least that's how it works in Postgres. In some other DBMS it might > work differently, but you're right back up against the fact that your > solution is not portable. > > Unique constraints (partial or otherwise) deal with the race-condition > problem by doing low-level things that aren't exposed at the SQL level. > So there's simply no way to get the equivalent behavior in pure standard > SQL. Thank you for the clarification, it's easy to understand now why using check constraints is a bad idea for the purpose I wanted to use them. It's also easy to see why 'proper' way is using partial unique indexes. Still, one has to wonder why there are no partial unique constraints defined in SQL standard :) Mario