database - 如何使用 PostgreSQL 中的特定表获取存储过程列表?

标签 database postgresql function plpgsql

在 PostgreSQL (9.3) 中是否有一种简单的方法来获取使用特定表的存储过程的列表?

我正在更改几个表,需要修复使用它们的存储过程。

最佳答案

在其主体中包含文本“thetable”的函数。

查询返回函数名、行号和包含'thetable'的行:

select *
from (
    select proname, row_number() over (partition by proname) as line, textline
    from (
        select proname, unnest(string_to_array(prosrc, chr(10))) textline
        from pg_proc p
        join pg_namespace n on n.oid = p.pronamespace
        where nspname = 'public'
        and prosrc ilike '%thetable%'
        ) lines
    ) x
    where textline ilike '%thetable%';

具有与 thetable 相关联的类型的任何参数或返回值的函数。

例如:

create function f2(rec thetable)...
create function f1() returns setof thetable... 

此查询给出函数的名称、返回类型和参数类型:

with rtype as (
    select reltype 
    from pg_class
    where relname = 'thetable')
select distinct on (proname) proname, prorettype, proargtypes
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
cross join rtype
where nspname = 'public'
and (
    prorettype = reltype 
    or reltype::text = any(string_to_array(proargtypes::text, ' '))) 

当然,您可以将查询合并为一个。我将它们用于不同的目的。

关于database - 如何使用 PostgreSQL 中的特定表获取存储过程列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31166303/

相关文章:

android - Android数据库同步

MySQL: bool 查询返回 true 如果用户没有设置 dnd 或者如果用户设置了 dnd 给定的 ID 必须是 friend

postgresql - 对表执行 DISABLE TRIGGER ALL 是否也会禁用 FK 指向该表?

sql - Postgres UPDATE..FROM 查询在同一行上有多个更新

javascript - Jquery,停止排队函数并重置为原始函数

javascript - 将函数返回的值打印到 javascript 中的屏幕

php - 通过 cronjob 组织数据库和多选列

sql - 十进制字段在 IBM AS400 的窗口上显示负数

postgresql - 导入 psycopg2

c++ - 数组奇怪的参数调理