Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YYeP6-0002fP-B3 for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Mar 2015 17:38:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YYeP5-0007Hy-Lu for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Mar 2015 17:38:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YYeP5-0007Hl-0C for pgsql-bugs@postgresql.org; Thu, 19 Mar 2015 17:38:43 +0000 Received: from smtprelay0105.b.hostedemail.com ([64.98.42.105] helo=smtprelay.b.hostedemail.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YYeP0-00021b-3d for pgsql-bugs@postgresql.org; Thu, 19 Mar 2015 17:38:41 +0000 Received: from filter.hostedemail.com (10.5.19.248.rfc1918.com [10.5.19.248]) by smtprelay03.b.hostedemail.com (Postfix) with ESMTP id 6F4B51A7013; Thu, 19 Mar 2015 17:38:36 +0000 (UTC) X-Session-Marker: 616C76686572726540616C76682E6E6F2D69702E6F7267 X-Spam-Summary: 13, 1.2, 0, , d41d8cd98f00b204, alvherre@alvh.no-ip.org, :::, RULES_HIT:41:152:355:379:599:800:960:967:973:982:988:989:1260:1263:1277:1311:1312:1313:1314:1345:1359:1431:1437:1515:1516:1518:1519:1534:1542:1593:1594:1595:1596:1711:1730:1747:1777:1792:2198:2199:2393:2525:2553:2560:2563:2682:2685:2693:2859:2903:2915:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4605:4659:5007:6261:7809:7875:7903:7904:8784:9025:9121:10008:10394:10400:10471:10848:10946:11232:11233:11256:11257:11658:11914:12043:12262:12438:12517:12519:12555:12679:12740:13161:13229:13255:13894:13895:21063:21080, 0, RBL:none, CacheIP:none, Bayesian:0.5, 0.5, 0.5, Netcheck:none, DomainCache:0, MSF:not bulk, SPF:fn, MSBL:0, DNSBL:none, Custom_rules:0:1:0 X-HE-Tag: voice65_6823499ceed5a X-Filterd-Recvd-Size: 3590 Received: from alvin.alvh.no-ip.org (186-105-105-136.baf.movistar.cl [186.105.105.136]) (Authenticated sender: alvherre@alvh.no-ip.org) by omf08.b.hostedemail.com (Postfix) with ESMTPA; Thu, 19 Mar 2015 17:38:35 +0000 (UTC) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id CA56919D5; Thu, 19 Mar 2015 14:38:25 -0300 (CLST) Date: Thu, 19 Mar 2015 14:38:25 -0300 From: Alvaro Herrera To: David G Johnston Cc: pgsql-bugs@postgresql.org Subject: Re: Re: BUG #11411: ALTER DOMAIN VALIDATE CONSTRAINT fails if the domain is used in a composite type Message-ID: <20150319173825.GL3636@alvh.no-ip.org> References: <20140912205148.2488.66328@wrigleys.postgresql.org> <1410570381842-5818911.post@n5.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1410570381842-5818911.post@n5.nabble.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org David G Johnston wrote: > Ondřej Bouda wrote > > The documentation for ALTER DOMAIN notes that "ALTER DOMAIN ADD CONSTRAINT > > and ALTER DOMAIN SET NOT NULL will fail if the named domain or any derived > > domain is used within a composite-type column of any table in the > > database." > > > > It appears current Postgres also fails on ALTER DOMAIN VALIDATE CONSTRAINT > > in such a case, as demonstrated by the following script: > TL/DR; The documentation needs some work here; and the code could be more > helpful - even without overcoming the limitation - though it likely isn't > worth the effort. Um. I have vague recollections about going some lengths to make sure this behaved sanely and usefully, i.e. validate tables that were using the domains. I guess I didn't cover all bases; seemed difficult enough as it was, back then. This behavior certainly seems unhelpful, because in effect you can never get a constraint validated. It doesn't look unduly complicated to drill down to composite types; maybe a good GSoC project? For reference, see this commit, in which Robert's last name was misspelled once again (sorry about that): commit 897795240cfaaed724af2f53ed2c50c9862f951f Author: Alvaro Herrera Date: Wed Jun 1 18:43:50 2011 -0400 Enable CHECK constraints to be declared NOT VALID This means that they can initially be added to a large existing table without checking its initial contents, but new tuples must comply to them; a separate pass invoked by ALTER TABLE / VALIDATE can verify existing data and ensure it complies with the constraint, at which point it is marked validated and becomes a normal part of the table ecosystem. An non-validated CHECK constraint is ignored in the planner for constraint_exclusion purposes; when validated, cached plans are recomputed so that partitioning starts working right away. This patch also enables domains to have unvalidated CHECK constraints attached to them as well by way of ALTER DOMAIN / ADD CONSTRAINT / NOT VALID, which can later be validated with ALTER DOMAIN / VALIDATE CONSTRAINT. Thanks to Thom Brown, Dean Rasheed and Jaime Casanova for the various reviews, and Robert Hass for documentation wording improvement suggestions. This patch was sponsored by Enova Financial. -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs