pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Manuel Rigger <rigger.manuel@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: ADD CHECK fails for parent table if column used in CHECK is fully-qualified
Date: Wed, 24 Jul 2019 22:09:52 -0400
Message-ID: <13268.1564020592@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+u7OA6Zs6bZmuakbLv4=7VBOYpBsyswpb7A3hN=n+KO0_z0pQ@mail.gmail.com>
References: <CA+u7OA6Zs6bZmuakbLv4=7VBOYpBsyswpb7A3hN=n+KO0_z0pQ@mail.gmail.com>

Manuel Rigger <rigger.manuel@gmail.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





view thread (2+ messages)

Message-ID: <13268.1564020592@sss.pgh.pa.us>
Permalink:  ../13268.1564020592@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/13268.1564020592@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, rigger.manuel@gmail.com
  Subject: Re: ADD CHECK fails for parent table if column used in CHECK is fully-qualified
  In-Reply-To: <13268.1564020592@sss.pgh.pa.us>
  References: <CA+u7OA6Zs6bZmuakbLv4=7VBOYpBsyswpb7A3hN=n+KO0_z0pQ@mail.gmail.com> <13268.1564020592@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox