Skip site navigation (1) Skip section navigation (2)

pg metadata and doc bug

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: pg metadata and doc bug
Date: 2008-11-25 19:47:07
Message-ID: alpine.DEB.2.00.0811252024360.20453@localhost.localdomain (view raw or flat)
Thread:
Lists: pgsql-hackers
Dear PostgreSQL developers,

#### 1

I stumbled upon an obscure bug (or undesirable feature:-) in the schema 
metadata accessible through the information_schema, and possibly 
pg_catalog as well. As it was mixed in a bug in some in my code, it was 
hard for me to identify it.

The issue is that when one does (in pg 8.3.5)

 	ALTER TABLE foo ADD CONSTRAINT xxx UNIQUE ON (...);

this results in a constraint *and* an index, but when one does only the 
corresponding:

 	CREATE UNIQUE INDEX foo(...);

then the index is created but there is no constraint. So what?

The consequence arises downhill when one declares a foreign key which uses 
this index as a target. The FK constraint is accepted, but as the metadata 
contents does not include the constraint, you cannot find the relevant 
informations by joining the various information_schema relations.

I was just looking for this information, how unlucky of me:-)

See the attached file for an example. Comment out the index creation and 
uncomment the unique constraint to see the difference in the metadata
(information_schema, and possibly underlying pg_catalog).

ITSM that the fix is that a 'CREATE UNIQUE INDEX...' shoud also add the 
corresponding constraint.


#### 2

Also, there is a minor bug in the documentation, which was the another 
source of my troubles:

  information_schema.KEY_COLUMN_USAGE.position_in_unique_constraint

is tagged as "NOT IMPLEMENTED", but it looks like it is implemented.

-- 
Fabien.

Attachment: test.sql
Description: text/plain (1.0 KB)

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2008-11-25 20:06:33
Subject: Re: pg metadata and doc bug
Previous:From: Tom LaneDate: 2008-11-25 19:42:15
Subject: Re: Exporting PGINTERVALSTYLE prevents access to older server versions

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group