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....
Another easiest and most used way to run any SQL file in PostgreSQL is via its SQL shell. Open the SQL shell from the menu bar of Windows 10. Add your server name, database name where you want to import the file, the port number you are currently active on, PostgreSQL username, and password to start using SQL shell.
For function:select proname,prosrc from pg_proc where proname= your_function_name; Another way is that just execute the commont \df and \ef which can list the functions. It will show the source code of the function.
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).
At the psql command line it's \df+ foo
, isn't it?
Eventually, select prosrc from pg_proc where proname='foo';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With