Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Zzkvw-00021E-Sv for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Nov 2015 12:36:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Zzkvw-0001zg-F8 for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Nov 2015 12:36:56 +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) (envelope-from ) id 1ZzLjD-0005A3-Am for pgsql-bugs@postgresql.org; Thu, 19 Nov 2015 09:42:07 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZzLjA-0004GV-26 for pgsql-bugs@postgresql.org; Thu, 19 Nov 2015 09:42:06 +0000 MIME-Version: 1.0 Subject: BUG #13779: Inherited check constraint becomes non-inherited when related column is changed To: pgsql-bugs@postgresql.org From: jan.dirk.zijlstra@redwood.com Date: Thu, 19 Nov 2015 09:41:26 +0000 Message-ID: <20151119094126.2574.12966@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 13779 Logged by: Jan Dirk Zijlstra Email address: jan.dirk.zijlstra@redwood.com PostgreSQL version: 9.4.5 Operating system: Linux Description: create table parenttable (a numeric, b numeric); create table childtable () inherits (parenttable); alter table parenttable add constraint parentconstraint_a check (a > 0); alter table parenttable add constraint parentconstraint_b check (b > 0); \d+ parenttable \d+ childtable select t.relname, c.conname, c.coninhcount, c.conislocal, c.connoinherit from pg_constraint c, pg_class t where c.conname like 'parentconstraint%' and c.conrelid = t.oid; alter table parenttable alter column a set data type real ; \d+ parenttable \d+ childtable select t.relname, c.conname, c.coninhcount, c.conislocal, c.connoinherit from pg_constraint c, pg_class t where c.conname like 'parentconstraint%' and c.conrelid = t.oid; drop table childtable; drop table parenttable; When executing the commands above, you'll notice that you have in the end a child table with a constraint which is not inherited anymore. This gives issues, because - you cannot drop the constraint on the parent table anymore. ( psql:tp.sql:86: ERROR: relation 23724254 has non-inherited constraint "parentconstraint_a" ) - you can drop the constraint on the child table, but than you can again not drop the constraint on the parent anymore. (psql:tp.sql:90: ERROR: constraint "parentconstraint_a" of relation "childtable" does not exist) - you cannot uninherit the child (psql:tp.sql:103: ERROR: relation 23724399 has non-inherited constraint "parentconstraint_a") To come out of this situation, I need to - drop the local constraint on the child table - drop the inheritance from the child table - drop the local constraint on the parent table - restore the inheritance on the child table - create the constraint again on the parent table. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs