Re: Walking a view to find all source tables - Mailing list pgsql-general

From Tom Lane
Subject Re: Walking a view to find all source tables
Date
Msg-id 29900.1021829485@sss.pgh.pa.us
Whole thread Raw
In response to Walking a view to find all source tables  ("Joel Burton" <joel@joelburton.com>)
Responses Re: Walking a view to find all source tables
List pgsql-general
"Joel Burton" <joel@joelburton.com> writes:
> During some debugging of a database tonight, I wrote this function that
> calls a view, examines its source, and recursively tracks down all the
> source tables.

A few comments:

>   if rec.relkind = ''r'' then return '''';

Probably be better to punt whenever relkind <> 'v', instead.

>   def := ev_action from pg_rewrite where ev_Class=rec.oid;

Will tend to fail if view has rules other than select (insert, delete,
update).  You'd better restrict the ev_type field too.


Also, I'd suggest making the internal recursion pass table oid not name;
will be a lot easier to adapt to 7.3, wherein relname is not unique.
(Although there may be better ways to do the whole thing in 7.3,
anyway --- need to review Rod Taylor's pg_depend patch again, but
probably some form of that will get in there.)

            regards, tom lane

pgsql-general by date:

Previous
From: "Joel Burton"
Date:
Subject: Re: LIMIT between some column
Next
From: Jean-Michel POURE
Date:
Subject: Re: [HACKERS] UTF-8 safe ascii() function