views:

41

answers:

3

How do you view a stored procedure/function?

Say I have an old function without the original definition - I want to see what it is doing in pg/psql but I can't seem to figure out a way to do that.

using Postgres version 8.4.1

A: 

Normally speaking you'd use a DB manager application like pgAdmin, browse to the object you're interested in, and right click your way to "script as create" or similar.

Are you trying to do this... without a management app?

annakata
Just the command line - no management app. If pgAdmin can do it, it has to be using some sort of command - I just can't find any documentation about it. I'm looking through the pg_* tables but none seem to stand out.
darren
Glad you found an answer, but not sure why you're making life hard for yourself! Why not just install pgAdmin?
annakata
A: 

use pgAdmin or use pg_proc to get the source of your stored procedures. pgAdmin does the same.

Frank Heikens
pg_proc that's it! Whew I'm glad they saved a few bytes of space by not calling it pg_procedure...geez. :)
darren
It's pretty easy to find out which queries psql is using to retrieve that information (e.g. for the \df command) by starting psql with the --echo-hidden parameter. That will show all queries that are used internally.pg_proc does not store a complete CREATE FUNCTION statement. You can use pg_get_functiondef() to retrieve the complete source.
a_horse_with_no_name
+1  A: 

\df+ <function_name> in psql.

Milen A. Radev
This works too, thanks!
darren