Re: Dependency tree to tie type/function deps to a table - Mailing list pgsql-general

From Jeremy Finzel
Subject Re: Dependency tree to tie type/function deps to a table
Date
Msg-id CAMa1XUjndazUcwBn5r_S0auKHGnpGj0NBBiatFCs13Dx-NR1vA@mail.gmail.com
Whole thread Raw
In response to Re: Dependency tree to tie type/function deps to a table  (Melvin Davidson <melvin6925@gmail.com>)
Responses Re: Dependency tree to tie type/function deps to a table
List pgsql-general
On Wed, Dec 13, 2017 at 9:54 AM, Melvin Davidson <melvin6925@gmail.com> wrote:


On Wed, Dec 13, 2017 at 10:20 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Jeremy Finzel <finzelj@gmail.com> writes:
> It looks like the very useful dependency tree shown when using DROP CASCADE
> is written in C in dependency.c, but there is no way to leverage this
> within Postgres to actually query an object's dependencies.  Can we get
> this somehow as a Postgres client in SQL?

Thanks Tom, I am working on this.
 

Seems like you could build a query for that easily enough using a
recursive union over pg_depend plus pg_describe_object() to produce
text descriptions of the entries.

                        regards, tom lane



Jeremy ,

per Tom

>Seems like you could build a query...

Attached is the query that I use. Hope that helps you.

--
Melvin Davidson
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.

I appreciate that, Melvin.  However, this doesn't do the recursive part.  It doesn't show me type or function dependencies, for example:

CREATE TEMP TABLE foo1 (id int);
CREATE TEMP TABLE foo2 (id int);
CREATE VIEW pg_temp.foo3 AS
SELECT f.id, f2.id AS id2
FROM foo1 f CROSS JOIN foo2 f2;
CREATE VIEW pg_temp.foo4 AS
SELECT f.id, f2.id AS id2
FROM foo1 f CROSS JOIN foo3 f2;

CREATE FUNCTION foo() RETURNS SETOF foo1 AS 'SELECT * FROM foo1;' LANGUAGE SQL;

Your function only shows:
  schema   |  parent   | dep_schema | dependent | type
-----------+-----------+------------+-----------+-------
 pg_temp_4 | foo1      | pg_temp_4  | foo3      | view
 pg_temp_4 | foo1      | pg_temp_4  | foo4      | view
 pg_temp_4 | foo2      | pg_temp_4  | foo3      | view
 pg_temp_4 | foo3      | pg_temp_4  | foo4      | view

Thanks,
Jeremy 

pgsql-general by date:

Previous
From: Göran Hasse
Date:
Subject: If table have an inclusion with LIKE what happens to triggers?
Next
From: Alvaro Herrera
Date:
Subject: Re: Dependency tree to tie type/function deps to a table