Re: find all views depend on a schema/table

From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: find all views depend on a schema/table
Date: 2014-01-27 04:42:06
Message-ID: 87k3dmrq75.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message ssylla 2014-01-27 08:39:56 Trigger function - variable for schema name
Previous Message Bob Spero 2014-01-27 00:20:25 How to detect values changed in field of foreign table?