Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqTCl-0000ib-Bs for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jul 2019 02:10:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hqTCj-00080v-SB for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jul 2019 02:10:01 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqTCj-00080F-JY for pgsql-bugs@lists.postgresql.org; Thu, 25 Jul 2019 02:10:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqTCc-0001fv-To for pgsql-bugs@lists.postgresql.org; Thu, 25 Jul 2019 02:10:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x6P29qiR013269; Wed, 24 Jul 2019 22:09:52 -0400 From: Tom Lane To: Manuel Rigger cc: PostgreSQL mailing lists Subject: Re: ADD CHECK fails for parent table if column used in CHECK is fully-qualified In-reply-to: References: Comments: In-reply-to Manuel Rigger message dated "Wed, 24 Jul 2019 12:00:11 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13267.1564020592.1@sss.pgh.pa.us> Date: Wed, 24 Jul 2019 22:09:52 -0400 Message-ID: <13268.1564020592@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Manuel Rigger writes: > Consider the following case: > CREATE TABLE t0(c0 boolean); > CREATE TABLE t1(c0 boolean) INHERITS(t0); > ALTER TABLE t0 ADD CHECK(t0.c0); > -- unexpected: ERROR: missing FROM-clause entry for table "t0" > Is it expected that this fails? I don't really have a problem with that. You specified that the check was on t0, and that would be an invalid constraint for t1. Now it is a bit weird that you can do this: regression=# CREATE TABLE t0(c0 boolean); CREATE TABLE regression=# ALTER TABLE t0 ADD CHECK(t0.c0); ALTER TABLE regression=# CREATE TABLE t1() INHERITS(t0); CREATE TABLE That happens because after the ALTER, the check constraint is remembered as just c0: regression=# \d t0 Table "public.t0" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- c0 | boolean | | | Check constraints: "t0_c0_check" CHECK (c0) and that can be propagated down to t1. So the system has forgotten a syntactic detail that perhaps it shouldn't have. But I can't get excited about changing that. regards, tom lane