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 1g2M9e-0005ly-6o for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Sep 2018 19:59:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g2M9b-0000xp-1O for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Sep 2018 19:59:23 +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 1g2M9a-0000xi-RU for pgsql-bugs@lists.postgresql.org; Tue, 18 Sep 2018 19:59:22 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g2M9T-0000G6-FS for pgsql-bugs@postgresql.org; Tue, 18 Sep 2018 19:59:22 +0000 Received: from [192.168.127.1] (port=57678 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1g2M9Q-000NoU-AS; Tue, 18 Sep 2018 19:59:12 +0000 Received: from [127.0.0.1] (port=62784 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1g2M9P-000OMo-Gi; Tue, 18 Sep 2018 19:59:11 +0000 From: Andrew Gierth To: Hristo Ivanov Cc: pgsql-bugs@postgresql.org Subject: Re: information_schema.check_constraints Inconsistencies In-Reply-To: (Hristo Ivanov's message of "Tue, 18 Sep 2018 21:16:05 +0300") Message-ID: <87fty6io5z.fsf@news-spur.riddles.org.uk> References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Tue, 18 Sep 2018 20:59:10 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Hristo" == Hristo Ivanov writes: Hristo> Hello, Hristo> I am writing with regards to some wrong results I keep on Hristo> receiving when using check_constraints view from Hristo> information_schema: Hristo> (1) First, it shows constraints grouped by name, regardless of Hristo> the relation used: when having two constraints with the same Hristo> name in different tables, it shows both in both tables, Hristo> regardless of their belonging; 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. https://wiki.postgresql.org/wiki/PostgreSQL_vs_SQL_Standard#Constraint_name_scope Hristo> (2) Second, it also lists NOT NULL constraints, even though Hristo> they are not created as check constraints. This is required by the SQL spec, which treats NOT NULL as merely a syntactic shorthand for CHECK(colname IS NOT NULL). But see also https://wiki.postgresql.org/wiki/PostgreSQL_vs_SQL_Standard#NOT_NULL_constraints_on_composite-type_columns which implies that for composite-type columns, NOT NULL and CHECK(colname IS NOT NULL) actually have different semantics in PG. -- Andrew (irc:RhodiumToad)