Re: find all views depend on a schema/table - Mailing list pgsql-sql

From Tim Landscheidt
Subject Re: find all views depend on a schema/table
Date
Msg-id 87k3dmrq75.fsf@passepartout.tim-landscheidt.de
Whole thread Raw
In response to find all views depend on a schema/table  (Emi Lu <emilu@encs.concordia.ca>)
List pgsql-sql
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




pgsql-sql by date:

Previous
From: Bob Spero
Date:
Subject: How to detect values changed in field of foreign table?
Next
From: ssylla
Date:
Subject: Trigger function - variable for schema name