PostgreSQL - How to show stored procedure code?
Using SQL Query:
You can use pg_proc
to show to stored procedure code:
SELECT prosrc FROM pg_proc WHERE proname = 'function_name';
However, pg_proc
does not display a complete CREATE FUNCTION statement
To show the full source code, use pg_get_functiondef()
:
SELECT
pg_get_functiondef((
SELECT
oid FROM pg_proc
WHERE
proname = 'function_name'));
For example, I want to show the source code of the function film_in_stock
:
SELECT
pg_get_functiondef((
SELECT
oid FROM pg_proc
WHERE
proname = 'film_in_stock'));
Using TablePlus GUI Tool for Postgres
You can see the complete source code of the function simple by clicking on the function name on the right panel.
Need a good GUI Tool for PostgreSQL? TablePlus is a modern, native tool with an elegant UI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.