Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3X6w-0002ne-Aw for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Apr 2017 00:16:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d3X6v-0006Sn-RF for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Apr 2017 00:16:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d3X6t-0006Pt-TZ; Thu, 27 Apr 2017 00:16:39 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3X6g-00071B-Rz; Thu, 27 Apr 2017 00:16:39 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id v3R0GJqf006097; Thu, 27 Apr 2017 09:16:19 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 324A45F63F; Thu, 27 Apr 2017 09:16:19 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 25D725F594; Thu, 27 Apr 2017 09:16:19 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 1CF9C400BA9; Thu, 27 Apr 2017 09:16:19 +0900 (JST) Subject: Re: [BUGS] BUG #14629: ALTER TABLE VALIDATE CONSTRAINTS does not obey NO INHERIT clause References: <20170421184012.24362.19@wrigleys.postgresql.org> <2035f652-cc33-3607-45b3-a024fdc9d47f@lab.ntt.co.jp> From: Amit Langote Message-ID: <183ee5e0-c2c9-fe41-8cb1-e8328a20194d@lab.ntt.co.jp> Date: Thu, 27 Apr 2017 09:16:06 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <2035f652-cc33-3607-45b3-a024fdc9d47f@lab.ntt.co.jp> Content-Type: multipart/mixed; boundary="------------1DE63DCA3282DAD2996DA172" To: buschmann@nidsa.net, pgsql-bugs@postgresql.org, Pg Hackers X-TM-AS-MML: disable X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------1DE63DCA3282DAD2996DA172 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 2017/04/24 13:16, Amit Langote wrote: > On 2017/04/22 3:40, buschmann@nidsa.net wrote: >> The following bug has been logged on the website: >> >> Bug reference: 14629 >> Logged by: Hans Buschmann >> Email address: buschmann@nidsa.net >> PostgreSQL version: 9.6.2 >> Operating system: Windows x64 >> Description: >> >> >> Given these both tables (orders_archiv inherits orders) on 9.6.2 Windows >> x64 >> (cut/paste from psql) >> >> xxxdb=# \d orders_archiv; >> ... >> Check constraints: >> "ck_or_old" CHECK (or_season < 24) NO INHERIT >> Inherits: orders >> >> >> xxxdb=# \d orders >> ... >> Check constraints: >> "ck_or_new" CHECK (or_season >= 24) NO INHERIT NOT VALID >> Triggers: >> tr_orders_insert BEFORE INSERT ON orders FOR EACH ROW WHEN >> (new.or_season < 24) EXECUTE PROCEDURE fn_orders_insert() >> Number of child tables: 1 (Use \d+ to list them.) >> >> >> When applying these commands to the parent table, the following errors are >> returned: >> >> xxxdb=# alter table orders validate constraint ck_or_new; >> ERROR: constraint "ck_or_new" of relation "orders_archiv" does not exist >> >> >> xxxdb=# alter table only orders validate constraint ck_or_new; >> ERROR: constraint must be validated on child tables too >> >> Background: >> From our original partitioning of quite a lot of tables according to >> xx_season columns (a season is a half year period) I dropped and recreated >> the check constraintsin a not valid state. >> >> At the end of the script to move the data from 2 seasons into the archiv >> tables I tried to reenable the check constraints and encountered those two >> errors. >> >> It seems that I can circumvent these errors by recreating the constraints >> without the not valid clause. >> >> Do I miss something here ? > > Looks indeed like a bug to me. Performing VALIDATE CONSTRAINT on what is > a non-inheritable constraint shouldn't look for that constraint in the > child tables. Attached patch fixes that. Should be applied in all of the > supported branches. Should have included -hackers when posting the patch. Here it is again for -hackers' perusal. Thanks, Amit --------------1DE63DCA3282DAD2996DA172 Content-Type: text/x-diff; name="0001-Fix-VALIDATE-CONSTRAINT-to-consider-NO-INHERIT-attri.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Fix-VALIDATE-CONSTRAINT-to-consider-NO-INHERIT-attri.pa"; filename*1="tch"