Re: getting oid of function

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Sibtay Abbas <sibtay(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: getting oid of function
Date: 2005-02-14 08:14:07
Message-ID: 20050214081407.GA3860@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Feb 14, 2005 at 12:47:44PM +0500, Sibtay Abbas wrote:
>
> Is it possible to get the oid of a function on the basis of its name?.

One way is to cast the function name to regproc (or, with arguments,
to regprocedure) and then to oid:

SELECT 'atan'::regproc::oid;
SELECT 'length(text)'::regprocedure::oid;

See "Object Identifier Types" in the documentation for more info:

http://www.postgresql.org/docs/8.0/static/datatype-oid.html

> The scenario which i am currently facing is that i have the function name, now
> i want search the pg_proc system catalog on the basis of the function
> name and retrieve its Oid.

SELECT oid FROM pg_proc WHERE proname = 'funcname';

A function can have multiple records in pg_proc if it can take
different types and/or numbers of arguments, so you might have to
allow for that.

> Another confusion which i am facing is that, I am not sure whether Oid
> of a function is entered in pg_proc system catalog or not. Because i
> am not able to identify any relevant field.

oid is a system column; tools that describe tables usually don't
show system columns. You can query pg_attribute to see all of a
table's columns.

http://www.postgresql.org/docs/8.0/static/ddl-system-columns.html
http://www.postgresql.org/docs/8.0/static/catalog-pg-attribute.html

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Hansen 2005-02-14 08:32:15 Schema name of function
Previous Message Sibtay Abbas 2005-02-14 07:47:44 getting oid of function