Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g2dXv-0002Zd-Lz for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Sep 2018 14:33:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g2dXt-0000mb-S8 for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Sep 2018 14:33:37 +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.89) (envelope-from ) id 1g2dXt-0000mQ-M3 for pgsql-bugs@lists.postgresql.org; Wed, 19 Sep 2018 14:33:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g2dXl-0008VV-Hw for pgsql-bugs@postgresql.org; Wed, 19 Sep 2018 14:33:35 +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 w8JEXMYq013870; Wed, 19 Sep 2018 10:33:22 -0400 From: Tom Lane To: Hristo Ivanov cc: Andrew Gierth , pgsql-bugs@postgresql.org Subject: Re: information_schema.check_constraints Inconsistencies In-reply-to: References: <87fty6io5z.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Hristo Ivanov message dated "Wed, 19 Sep 2018 09:31:42 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13868.1537367602.1@sss.pgh.pa.us> Date: Wed, 19 Sep 2018 10:33:22 -0400 Message-ID: <13869.1537367602@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hristo Ivanov writes: > 2018-09-18 22:59 GMT+03:00 Andrew Gierth : >> In the SQL spec, the name of a constraint is not local to the table; in >> a given schema, the name must be unique. PostgreSQL does not enforce >> this, and generally treats constraint names as local to a single >> _table_; this is difficult to fix retroactively because it would make >> old databases fail to restore if the spec's conditions were enforced. > I didn't know that constraint names had to be unique. Even if that is true, > I don't think returning wrong constraints in this case (belonging to a > different table) is the right thing to do. This means that PostgreSQL is > conforming to the standard in only places, while the dependencies are > clearly not standard compliant. Since the likelihood of fixing dependencies > is fairly small, I would suggest fixing the constraints selection behavior. It was already explained to you that we're not changing this. The information_schema outputs conform to the spec as long as the inputs (i.e., the set of constraint names created by your application) do. It's not very plausible to insist on spec compliance for what you see in information_schema when the violation is your own fault. Moreover, the only thing we could do to make the situation more compliant would be to enforce constraint name uniqueness schema-wide, which is not really very desirable (on any metric other than blind standards compliance) and would create major backwards-compatibility issues. So no, it's not going to change. > Fair enough. Could I suggest having a column to discriminate non-null > constraints from the rest? Not in the information_schema you can't :-(. The set of columns in those views is dictated by the standard. Adding more would just be another way of not being compliant. > FYI, the only solution I found to this problem, is: ... > This completely disregards the information_schema objects. Yup, if you want to deal with non-standard-compliant objects or situations, you generally need to ignore information_schema and look directly at the catalogs. regards, tom lane