Обсуждение: find all views depend on a schema/table

Поиск
Список
Период
Сортировка

find all views depend on a schema/table

От
Emi Lu
Дата:
Hello,

Is there a simple way to query all views depend on a schema or table?

E.g.,
view_schema| view_name | depends on schema_name | depends on t1
===========|===========|========================|================
v_schema   |v1         | test                   | t1

"v_schema.v1" is defined as select .... from test.t1... where;


Thanks a lot!



Re: find all views depend on a schema/table

От
Tom Lane
Дата:
Emi Lu <emilu@encs.concordia.ca> writes:
> Is there a simple way to query all views depend on a schema or table?

Well, you could build something that examines pg_depend, or you could
try this:

begin;
drop table some_table restrict;
... note what it complains about ...
rollback;
        regards, tom lane



Re: find all views depend on a schema/table

От
Emi Lu
Дата:
>> Is there a simple way to query all views depend on a schema or table?
> Well, you could build something that examines pg_depend, or you could
> try this:

Thank you. I will try to find mapped results for pg_depend.

> begin;
> drop table some_table restrict;
> ... note what it complains about ...
> rollback;

No... to find all views(not in schema1) depend on any schema1.objects.










Re: find all views depend on a schema/table

От
Tim Landscheidt
Дата:
Tom Lane <tgl@sss.pgh.pa.us> wrote:

>> Is there a simple way to query all views depend on a schema or table?

> Well, you could build something that examines pg_depend, or you could
> try this:

> begin;
> drop table some_table restrict;
> ... note what it complains about ...
> rollback;

Note that neither show dependencies that are "hidden" in
functions, i. e.:

| tim=# CREATE TABLE T (ID INT PRIMARY KEY);
| NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "t_pkey" for table "t"
| CREATE TABLE
| tim=# CREATE FUNCTION F() RETURNS INT AS 'SELECT MIN(ID) FROM T;' LANGUAGE SQL;
| CREATE FUNCTION
| tim=# CREATE VIEW V AS SELECT F();
| CREATE VIEW
| tim=# DROP TABLE T;
| DROP TABLE
| tim=# SELECT * FROM V;
| ERROR:  relation "t" does not exist
| LINE 1: SELECT MIN(ID) FROM T;
|                             ^
| QUERY:  SELECT MIN(ID) FROM T;
| CONTEXT:  SQL function "f" during inlining
| tim=#

Tim