Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 83DFE1337B4E for ; Wed, 23 Feb 2011 00:33:54 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 50236-10 for ; Wed, 23 Feb 2011 04:33:47 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from momjian.us (momjian.us [70.90.9.53]) by mail.postgresql.org (Postfix) with ESMTP id A9FBB1337B47 for ; Wed, 23 Feb 2011 00:33:46 -0400 (AST) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id p1N4Xhf00498; Tue, 22 Feb 2011 23:33:43 -0500 (EST) From: Bruce Momjian Message-Id: <201102230433.p1N4Xhf00498@momjian.us> Subject: Re: [BUGS] issue about information_schema REFERENTIAL_CONSTRAINTS In-Reply-To: To: Fabien COELHO Date: Tue, 22 Feb 2011 23:33:43 -0500 (EST) CC: Peter Eisentraut , Tom Lane , Alvaro Herrera , pgsql-docs@postgresql.org, Tom Lane X-Mailer: ELM [version 2.4ME+ PL124 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/77 X-Sequence-Number: 6425 Fabien COELHO wrote: > > Hello Bruce, > > >>>> Is that the direction we want to go, or would it be better to factor > >>>> the information out into a separate page about compatibility gotchas? > >>> > >>> It would probably be better to explain globally applicable issues in a > >>> separate section. > >> > >> I agree that a general caveat is better, together with a one line > >> reference in the documentation of each table with an issue. > > > > Oh, I just noticed this. Can you give me a list of information_schema > > tables that have this issue? I am only aware of > > referential_constraints. > > Possibly any relation which references constraints with a (catalog, > schema, name) triplet expecting it to be unique should have this issue. > > >From a quick scan on the information_schema, I would say: > - check_constraint_routine_usage > - check_constraints > - constraint_column_usage (*) > - constraint_table_usage (*) > - domain_constraints > - referential_constraints > - table_constraints (*) > > For the three starred relations, the issue is not too big because a > constraint name is unique per table in pgsql, and the table name is also > given in these relations. > > This issue makes the "information_schema" pretty useless for being really > use for serious work as the data can be ambiguous, so I still claim that > for me this is a real "bug" rather than just a "feature", which is the > status reached once a bug is documented:-) > > When constraint names are generated by postgresql, ISTM that the software > is free to choose them so they could be chosen non ambiguous per schema. > > When users choose colliding names, I agree that it would break existing > schemas, but there could be an option to enforce uniqueness of the name > per schema if desired. > > I know there are some underlying issues with that that were discussed > previously. > > Anyway I would appreciate something that it appears in the "todo" list, > even if it is never implemented:-) OK, based on the view list above and Tom's request, I have added an additional paragraph to the documenation naming the views which might be affected by duplicated named constraints; the second paragraph is the paragraph I added: When querying the database for constraint information, it is possible for a standard-compliant query that expects to return one row to return several. This is because the SQL standard requires constraint names to be unique within a schema, but PostgreSQL does not enforce this restriction. PostgreSQL automatically-generated constraint names avoid duplicates in the same schema, but users can specify such duplicate names. This problem can appear when querying information schema views like referential_constraints, check_constraints, domain_constraints, and check_constraint_routine_usage. Some other views have similar issues but contain the table name to help distinguish duplicate rows, e.g. table_constraints, constraint_table_usage, constraint_column_usage. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. +