I just noticed that PostgreSQL allows repeating foreign key (and possibly other constraint) names across the database as long as they are on a different table.
So if the parent table is Foo
and it has two child tables BarX
and BarY
, the foreign keys on both tables can be named FK_fooid
.
This, IMO, is a terrible design because
select * from information_schema.referential_constraints
where constraint_name = 'FK_fooid'
will return two identical rows with no ability to differentiate which one corresponds to which table/key.
Is there a way to disable repetition of constraint names across a database in Postgres and to enforce that each constraint has a unique name?
Best Answer
Then don't use
information_schema
:Example: http://rextester.com/DAR30737