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

Finding all tables that have foreign keys referencing a table

From: Andreas Joseph Krogh <andreak(at)officenet(dot)no>
To: pgsql-sql(at)postgresql(dot)org
Subject: Finding all tables that have foreign keys referencing a table
Date: 2008-11-06 21:35:23
Message-ID: 200811062235.23267.andreak@officenet.no (view raw or flat)
Thread:
Lists: pgsql-sql
Hi.
I see the last comment here suggests a solution for $subject:
http://www.postgresql.org/docs/8.1/interactive/ddl-constraints.html

But it turns out it assumes constraint_name is unique, which is not the case. It is only unique pr. table. In other words, it produces a lot of false results.

I'm trying to make a function which finds all my old "$1" constraints and replaces those names with proper names (_fkey).

So - anybody who knows a good solution for how to find all tables with constraint-names that have foreign keys referencing a table's particluar colum?

-- 
Andreas Joseph Krogh <andreak(at)officenet(dot)no>
Senior Software Developer / CEO
------------------------+---------------------------------------------+
OfficeNet AS            | The most difficult thing in the world is to |
Karenslyst Allé 11      | know how to do a thing and to watch         |
PO. Box 529 Skøyen      | somebody else doing it wrong, without       |
0214 Oslo               | comment.                                    |
NORWAY                  |                                             |
Tlf:    +47 24 15 38 90 |                                             |
Fax:    +47 24 15 38 91 |                                             |
Mobile: +47 909  56 963 |                                             |
------------------------+---------------------------------------------+

Responses

pgsql-sql by date

Next:From: Markus SchattenDate: 2008-11-07 12:07:34
Subject: Creating input/output_functions
Previous:From: Harold A. Giménez Ch.Date: 2008-11-06 17:10:24
Subject: Re: need help in building a query

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