Re: ADD CHECK fails for parent table if column used in CHECK is fully-qualified

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Manuel Rigger <rigger(dot)manuel(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: ADD CHECK fails for parent table if column used in CHECK is fully-qualified
Date: 2019-07-25 02:09:52
Message-ID: 13268.1564020592@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Manuel Rigger <rigger(dot)manuel(at)gmail(dot)com> 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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2019-07-25 03:08:34 Re: A function privilege problem
Previous Message 高 云龙 2019-07-25 02:05:24 Re: A function privilege problem