Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d2VRr-00044M-KE for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Apr 2017 04:18:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d2VRq-0007GL-0m for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Apr 2017 04:18:02 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d2VR7-00060a-VU for pgsql-bugs@postgresql.org; Mon, 24 Apr 2017 04:17:18 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d2VQz-0004JX-2T for pgsql-bugs@postgresql.org; Mon, 24 Apr 2017 04:17:15 +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 v3O4H2Gl032318; Mon, 24 Apr 2017 13:17:02 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 11C145F631; Mon, 24 Apr 2017 13:17:02 +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 051AB5F594; Mon, 24 Apr 2017 13:17:02 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 06F45400C25; Mon, 24 Apr 2017 13:17:02 +0900 (JST) Subject: Re: BUG #14629: ALTER TABLE VALIDATE CONSTRAINTS does not obey NO INHERIT clause References: <20170421184012.24362.19@wrigleys.postgresql.org> From: Amit Langote Message-ID: <2035f652-cc33-3607-45b3-a024fdc9d47f@lab.ntt.co.jp> Date: Mon, 24 Apr 2017 13:16:51 +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: <20170421184012.24362.19@wrigleys.postgresql.org> Content-Type: multipart/mixed; boundary="------------24A449C44AE0D6772102A728" To: buschmann@nidsa.net, pgsql-bugs@postgresql.org 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-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------24A449C44AE0D6772102A728 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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. Thanks, Amit --------------24A449C44AE0D6772102A728 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"