Function exists

Started by Mihai Gheorghiuover 24 years ago2 messagesgeneral
Jump to latest
#1Mihai Gheorghiu
tanethq@earthlink.net

I want to write a function that finds out whether a function already exists.
Is that possible? How?
Thank you all.

#2Marko Kreen
markokr@gmail.com
In reply to: Mihai Gheorghiu (#1)
Re: Function exists

On Tue, Sep 25, 2001 at 02:20:23PM -0400, Mihai Gheorghiu wrote:

I want to write a function that finds out whether a function already exists.
Is that possible? How?

select * from pg_proc where proname = ??;

you can run psql with switch -E, then it shows intenal queries
it performs. Eg., for \df - 'show functions' it does:

$ psql -E
marko=# \df
********* QUERY *********
SELECT format_type(p.prorettype, NULL) as "Result", p.proname as
"Function",
oidvectortypes(p.proargtypes) as "Arguments"
FROM pg_proc p
WHERE p.prorettype <> 0 and (pronargs = 0 or
oidvectortypes(p.proargtypes) <> '')
ORDER BY "Function", "Result", "Arguments"
*************************

from there you can hack further.

--
marko