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