Created
September 1, 2011 19:11
-
-
Save adunstan/1186988 to your computer and use it in GitHub Desktop.
See which tables are called in a view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION public.viewtables(viewname text) | |
RETURNS SETOF text | |
LANGUAGE plperl | |
AS $function$ | |
my $viewname = shift; | |
my $rv = spi_exec_query("explain (format yaml, verbose) SELECT * FROM $viewname"); | |
my $resp = $rv->{rows}[0]->{'QUERY PLAN'}; | |
my %tbls; | |
while ($resp =~ /Relation Name: (".*")\n\s+Schema: (".*")\n/g) | |
{ | |
$tbls{"$2.$1"} = 1; | |
} | |
return [sort keys %tbls]; | |
$function$ | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment