PostgreSQL-视图-03-查询对象依赖关系视图-dba_dependencies

PostgreSQL查询对象依赖关系视图

sql 复制代码
-- 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
;
相关推荐
Elias不吃糖23 分钟前
Qt 6以上版本都试用 连接 MySQL 数据库全流程(CMake 环境)
数据库·qt·mysql
不是二师兄的八戒24 分钟前
MySQL 中 HAVING 子句的深度解析与实战指南
数据库·mysql
l1t39 分钟前
Duckdb rusty_sheet插件使用心得
数据库·sql·lua·duckdb·rusty_sheet
asdfsdgss1 小时前
PostgreSQL 教程:json 与 jsonb 的数据验证机制差异及实战选择
数据库·postgresql·json
座山雕~1 小时前
MYSQL-超全基础以及用法--仅个人的速记笔记(1)
数据库·mysql
喜欢读源码的小白1 小时前
Spring Boot+MyBatis实现无限层级组织架构设计|邻接表vs闭包表性能对比|树形结构数据存储方案
java·数据库·组织结构·树级层级·无线层级
FJW0208141 小时前
关系型数据库大王Mysql——DML语句操作示例
数据库·mysql
禁默1 小时前
基于金仓KFS工具,破解多数据并存,浙人医改造实战医疗信创
数据库·人工智能·金仓数据库
pen-ai2 小时前
【数据工程】15. Stream Query Processing
数据库
it码喽2 小时前
Redis存储经纬度信息
数据库