Way to check for function existance

Started by Jim Nasbyover 21 years ago2 messagesgeneral
Jump to latest
#1Jim Nasby
Jim.Nasby@BlueTreble.com

Sorry if this has been covered before, but the mailing list search is
down right now.

What's the best way to check for the existance of a function? I saw
pg_function_is_visible(), but the problem is that I'd need to use
::regprocedure with it, and ::regprocedure generates an error if the
function doesn't exist. Since I can't trap the error in pgplsql that's
no use.

I'm also working on trying to do a select out of pg_proc, but I'm not
having a lot of luck there either...

# select oid,* from pg_proc where proname='user_write_lock_oid' and
proargtypes = ARRAY((SELECT oid FROM pg_type WHERE
typname='oid'))::oidvector;
ERROR: cannot cast type oid[] to oidvector

--
Jim C. Nasby, Database Consultant decibel@decibel.org
Give your computer some brain candy! www.distributed.net Team #1828

Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jim Nasby (#1)
Re: Way to check for function existance

"Jim C. Nasby" <decibel@decibel.org> writes:

I'm also working on trying to do a select out of pg_proc, but I'm not
having a lot of luck there either...

# select oid,* from pg_proc where proname='user_write_lock_oid' and
proargtypes = ARRAY((SELECT oid FROM pg_type WHERE
typname='oid'))::oidvector;
ERROR: cannot cast type oid[] to oidvector

For standard types like OID, it's probably easiest just to hardwire the
oidvector value:
select ...
where proname='user_write_lock_oid' and pronargs = 1 and proargtypes = '26';
Note you should include the pronargs test to allow this to match the
index on pg_proc.

regards, tom lane