Re: How do I find what views depend on a particular table?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Justin Tocci <jtocci(at)tlcusa(dot)com>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How do I find what views depend on a particular table?
Date: 2003-08-25 14:31:17
Message-ID: 15008.1061821877@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Justin Tocci <jtocci(at)tlcusa(dot)com> writes:
> I've found the pg_depend table, but it doesn't appear to include this info.
> (Or am I missing it?)

You're missing it.

IIRC, the dependency is actually from the view's ON SELECT rule to the
tables (and other objects) mentioned in the rule. There is also a
dependency from the ON SELECT rule to the view itself. This latter
dependency is marked INTERNAL, which (a) prevents you from dropping the
ON SELECT rule by itself, and (b) tells a DROP CASCADE that reaches the
rule to cascade up to the view. See the discussion at
http://developer.postgresql.org/docs/postgres/catalog-pg-depend.html

> Alternately, I would be happy with a way to get the names of objects that
> are dropped when DROP CASCADE is used.

You can do

BEGIN;
DROP foo CASCADE;
ROLLBACK;

and examine the set of NOTICEs emitted by the DROP. This is perhaps not
very amenable to mechanization :-(

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jenny - 2003-08-25 14:45:40 LOCK.tag(figuring out granularity of lock)--
Previous Message Carlos 2003-08-25 13:54:57 Space occupied by an image in a byte field?