6

As we are using sp_helptext [procedure name] to get the SP script in Sqlserver, I need the command that i can use to retrieve a function script from postgresql.

Please help....

1

2 Answers 2

9

If you are using psql (the commandline interface) you can use \df+ as tobixen has already stated (and which is clearly documented in the manual).

If you need to do this from within a SQL query, take a look a the system information functions. You are looking for pg_get_functiondef()

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

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

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

will retrieve the overloaded versions of the function foo (one version with a single int parameter, the other version with two int parameters).

Sign up to request clarification or add additional context in comments.

Comments

4

At the psql command line it's \df+ foo, isn't it?

Other than that, select prosrc from pg_proc where proname='foo';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.