SELECT
r.table_name
FROM information_schema.constraint_column_usage u
INNER JOIN information_schema.referential_constraints fk
ON u.constraint_catalog = fk.unique_constraint_catalog
AND u.constraint_schema = fk.unique_constraint_schema
AND u.constraint_name = fk.unique_constraint_name
INNER JOIN information_schema.key_column_usage r
ON r.constraint_catalog = fk.constraint_catalog
AND r.constraint_schema = fk.constraint_schema
AND r.constraint_name = fk.constraint_name
WHERE
u.column_name = 'id' AND
u.table_catalog = 'db_name' AND
u.table_schema = 'public' AND
u.table_name = 'table_a'
Dette bruger det fulde katalog/skema/navn-triplet til at identificere en db-tabel fra alle 3 informationsskemavisninger. Du kan droppe en eller to efter behov.
Forespørgslen viser alle tabeller, der har en fremmednøglebegrænsning mod kolonnen 'a' i tabel 'd'