OID of current function

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

Is there an easy way to get the OID of the currently running function?
(IE: the function you're in when you execute the code to see what
function you're in, if that makes any sense).
--
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?"

#2Thomas Hallgren
thhal@mailblocks.com
In reply to: Jim Nasby (#1)
Re: OID of current function

Jim C. Nasby wrote:

Is there an easy way to get the OID of the currently running function?
(IE: the function you're in when you execute the code to see what
function you're in, if that makes any sense).

In what language? In C you can use:

Datum your_function(PG_FUNCTION_ARGS)
{
Oid funcOid = fcinfo->flinfo->fn_oid;
...
}

Regards,
Thomas Hallgren

#3Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Thomas Hallgren (#2)
Re: OID of current function

On Wed, Jan 12, 2005 at 04:08:28PM +0100, Thomas Hallgren wrote:

Jim C. Nasby wrote:

Is there an easy way to get the OID of the currently running function?
(IE: the function you're in when you execute the code to see what
function you're in, if that makes any sense).

In what language? In C you can use:

Datum your_function(PG_FUNCTION_ARGS)
{
Oid funcOid = fcinfo->flinfo->fn_oid;
...
}

This would be in plpgsql.

Some other info:

What I'm trying to do is use contrib/userlock to serialize access to a
function. The only effective way to come up with a unique lock number
that I've been able to think of is to use the OID of the function
itself.

What I find somewhat interesting is every other database I've used that
exposes some kind of 'object ID' has a set of functions to map between
an object name and it's ID, and vice-versa. It seems like this is
something that would be good for PostgreSQL to have.
--
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?"

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jim Nasby (#3)
Re: OID of current function

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

What I find somewhat interesting is every other database I've used that
exposes some kind of 'object ID' has a set of functions to map between
an object name and it's ID, and vice-versa.

regression=# create function myfunc(int) returns int as 'select $1' language sql;
CREATE FUNCTION

regression=# SELECT 'myfunc(int)'::regprocedure::oid;
oid
--------
431373
(1 row)

regression=# select 431373::regprocedure;
regprocedure
-----------------
myfunc(integer)
(1 row)

regards, tom lane