PostgreSQL查询对象依赖关系视图文章来源地址https://www.toymoban.com/news/detail-613655.html
-- PostgreSQL查询对象依赖关系视图
drop view if exists tzq.dba_dependencies;
create view tzq.dba_dependencies as
with source_obj as (
select sp.oid,sp.proname
,unnest(
string_to_array(
regexp_replace(
regexp_replace(lower(sp.prosrc),'--.*?\n'::text, ''::text, 'g'::text)
,'\W+'::text, ' '::text, 'g'::text)
, ' '::text)
)
as split_text
,sp.proowner::regrole::character varying as schema_name
,sp.proowner
from pg_proc sp
where (sp.proowner in (select pg_user.usesysid
from pg_user
where pg_user.usename ~~ 'tzq%'::text or
pg_user.usename = 'jdbc_etl_in'::name or
pg_user.usename = 'ewf'::name
))
)
,all_depend as (
select t.schema_name as owner
,t.proname as name
,'procedure'::text as type
,p.proowner::regrole::character varying as referenced_owner
,p.proname as referenced_name
,'procedure'::text as referenced_type
,p.proowner
from source_obj t
join pg_proc p
on t.split_text = p.proname
and p.proowner <> 10::oid
union all
select t.schema_name as owner
,t.proname as name
,'procedure'::text as type
,p.schemaname as referenced_owner
,p.tablename as referenced_name
,'table'::text as referenced_type
,t.proowner
from source_obj t
join pg_tables p
on t.split_text = p.tablename
and (p.schemaname ~~ 'tzq%'::text or
p.schemaname = 'jdbc_etl_in'::name or
p.schemaname = 'ewf'::name)
)
select distinct
owner
,name
,type
,referenced_owner
,referenced_name
,referenced_type
from all_depend
;
文章来源:https://www.toymoban.com/news/detail-613655.html
到了这里,关于PostgreSQL-视图-03-查询对象依赖关系视图-dba_dependencies的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!