dependency ?

Started by Nonameabout 19 years ago3 messagesgeneral
Jump to latest
#1Noname
TWENGER2@wi.rr.com

Hi,
I was wondering if there is any way to use psql to list tables that
are dependent to a specific table. Instead of going through every table
in my database and looking for foreign keys, can I somehow get an entire
list of these dependent tables? Any help would be much appreciated, thanks!

Tyson

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Noname (#1)
Re: dependency ?

TWENGER2@wi.rr.com writes:

I was wondering if there is any way to use psql to list tables that
are dependent to a specific table. Instead of going through every table
in my database and looking for foreign keys, can I somehow get an entire
list of these dependent tables? Any help would be much appreciated, thanks!

pg_depend might help, although I think it'd be a multi-step link.

regards, tom lane

#3Brian Wipf
brian@clickspace.com
In reply to: Noname (#1)
Re: dependency ?

On 29-Jan-07, at 1:06 PM, TWENGER2@wi.rr.com wrote:

I was wondering if there is any way to use psql to list tables that
are dependent to a specific table. Instead of going through every
table
in my database and looking for foreign keys, can I somehow get an
entire
list of these dependent tables? Any help would be much
appreciated, thanks!

You could do this easily enough in the shell. For example, If I
wanted to find all tables that reference foo_table:

psql -U postgres database_name -c '\d *' | egrep "(Table |REFERENCES
foo_table)" | grep -B1 'REFERENCES foo_table' | grep 'Table ' | cut -
d '"' -f 2

should do the trick.

Brian Wipf