What is the command to find the script of an existing function in postgresql?

Since we use sp_helptext [procedure name] to get the SP script in Sqlserver, I need a command that I can use to extract the script function from postgresql.

Please, help....

+5
source share
2 answers

If you use psql (command line interface), you can use \df+, as already mentioned (and this is clearly indicated in the manual).

If you need to do this from an SQL query, take a look at the system information functions . You are looking forpg_get_functiondef()

select pg_get_functiondef(oid)
from pg_proc
where proname = 'your_function';

If you are dealing with overloaded functions that have a different number of parameters, you need to include the parameter signature in the name:

select pg_get_functiondef('public.foo(int)'::regprocedure);
select pg_get_functiondef('public.foo(int,int)'::regprocedure);

foo ( int, int).

+7

psql \df+ foo, ?

, select prosrc from pg_proc where proname='foo';

+3

All Articles