Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 0108CB5DBD0 for ; Sat, 6 Aug 2011 07:03:24 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 94792-06 for ; Sat, 6 Aug 2011 10:03:17 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.22]) by mail.postgresql.org (Postfix) with SMTP id 14CBAB5DBC1 for ; Sat, 6 Aug 2011 07:03:16 -0300 (ADT) Received: (qmail invoked by alias); 06 Aug 2011 10:03:16 -0000 Received: from a88-115-218-165.elisa-laajakaista.fi (EHLO [10.0.0.102]) [88.115.218.165] by mail.gmx.net (mp044) with SMTP; 06 Aug 2011 12:03:16 +0200 X-Authenticated: #495269 X-Provags-ID: V01U2FsdGVkX1/KmlIqk+PKThzyy67jzXu8o/j39mkO8cbaTvn1kX LSun1c84+Wjwps Subject: Re: cataloguing NOT NULL constraints From: Peter Eisentraut To: Dean Rasheed Cc: Alvaro Herrera , Robert Haas , Pg Hackers In-Reply-To: References: <20110707213401.GA27098@alvh.no-ip.org> <1311291819-sup-6206@alvh.no-ip.org> <1311367030-sup-9426@alvh.no-ip.org> <1311985058-sup-952@alvh.no-ip.org> <1312342392-sup-7189@alvh.no-ip.org> <1312480674.24208.8.camel@vanquo.pezone.net> Content-Type: text/plain; charset="UTF-8" Date: Sat, 06 Aug 2011 13:03:13 +0300 Message-ID: <1312624993.24721.16.camel@vanquo.pezone.net> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 Content-Transfer-Encoding: 8bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.83 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-0.931 X-Spam-Level: X-Archive-Number: 201108/294 X-Sequence-Number: 193049 On lör, 2011-08-06 at 08:04 +0100, Dean Rasheed wrote: > On 4 August 2011 18:57, Peter Eisentraut wrote: > > Have you considered just cataloging NOT NULL constraints as CHECK > > constraints and teaching the reverse parser to convert "x CHECK (x IS > > NOT NULL)" to "x NOT NULL". It seems to me that we're adding a whole > > lot of hoopla here that is essentially identical to the existing CHECK > > constraint support (it must be, per SQL standard), for no additional > > functionality. > > > > With this approach, if the user explicitly wrote "CHECK (x IS NOT > NULL)" would it end up setting attnotnull? Yes, I would assume so. > Presumably, since the > pg_constraint entry would be indistinguishable, it would be difficult > to do otherwise. From a performance standpoint that might be a good > thing, but it's going to be bad for compatibility. What compatibility issue are you concerned about specifically? > What if they wrote "CHECK (NOT x IS NULL)", or "CHECK (x IS DISTINCT > FROM NULL)"? How many variants would it reverse parse? Well, it's already the case that the user can write check constraints in any number of forms that have the effect of restricting null values; and attnotnull isn't set in those cases. So in the beginning I'd be quite happy if we just recognized CHECK (x IS NOT NULL). Longer term, I think we could tie this in with more general nullability detection. For example, it is occasionally asked that we can expose nullability through views or CREATE TABLE AS. The SQL standards has rules for what cases we should detect (which don't include the two you give). > What would this do to error messages when the constraint is violated? That's a reasonable concern, although not a fatal one, and it can be solved in any case. > I'm not convinced this simplifies things much; it just moves the > complexity elsewhere, and at the cost of losing compatibility with the > current behaviour. No, I don't think this would lose compatibility (except perhaps in cases of error message wording).