Re: information_schema.constraint_column_usage shows wrong table name

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alex Zeng <Alex(dot)Zeng(at)datam(dot)co(dot)nz>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: information_schema.constraint_column_usage shows wrong table name
Date: 2021-08-10 15:51:23
Message-ID: 3788089.1628610683@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Alex Zeng <Alex(dot)Zeng(at)datam(dot)co(dot)nz> writes:
> When creating a constraint from table A to table B, the table name and column name in information_schema.constraint_column_usage shows table B. That makes impossible to check whether a constraint exists as we can have a constraint from table C to B and they will have same value in information_schema.constraint_column_usage.

The SQL standard says the purpose of this view is to

Identify the columns used by referential constraints, unique
constraints, check constraints, and assertions defined in this catalog
and owned by a given user or role.

so I think the view is showing the column name it is supposed to,
ie the referenced column name not the referencing column name.
The key_column_usage view might help you with the other thing.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Rainer Tammer 2021-08-10 16:14:32 Postgres 9.2.13 on AIX 7.1
Previous Message David G. Johnston 2021-08-10 13:48:55 Re: BUG #17139: Invalid input syntax for uuid (politely this time!)