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

Ala*_*yne 4 database postgresql function plpgsql

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

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

kli*_*lin 5

体内带有“桌子”文字的功能。

该查询返回函数名称,行号和包含“ 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%';
Run Code Online (Sandbox Code Playgroud)

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

例如:

create function f2(rec thetable)...
create function f1() returns setof thetable... 
Run Code Online (Sandbox Code Playgroud)

该查询提供函数的名称,返回类型和参数类型:

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, ' '))) 
Run Code Online (Sandbox Code Playgroud)

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