Get all procedural , user defined functions

情到浓时终转凉″ 提交于 2019-11-30 04:14:07
Craig Ringer

Consider:

select 
    pp.proname,
    pl.lanname,
    pn.nspname,
    pg_get_functiondef(pp.oid)
from pg_proc pp
inner join pg_namespace pn on (pp.pronamespace = pn.oid)
inner join pg_language pl on (pp.prolang = pl.oid)
where pl.lanname NOT IN ('c','internal') 
  and pn.nspname NOT LIKE 'pg_%'
  and pn.nspname <> 'information_schema';

See also: What is the command to find script of a existing function in postgresql?

Use pg_get_functiondef or the prosrc column from pg_proc directly. The key idea is to join on pg_namespace and filter out the PostgreSQL catalog functions, which will probably be adequate for most purposes:

FROM pg_proc pp INNER JOIN pg_namespace ON (pp.pronamespace = pn.oid)
WHERE pn.nspname <> 'pg_catalog'

The trouble with obtaining the source code for user defined functions is deciding what user means. Many types of functions can be created:

  • Functions using CREATE EXTENSION.
  • Functions created by PostgreSQL.
  • Functions compiled and installed by an administrator.

Superusers with sufficent grants can define functions in pg_proc, but usually don't.

Since only superusers can create C language functions, exclude them. Such functions can be custom-installed on a particular database by the admin, but not a normal user.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!