Re: Schema name of function - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Schema name of function
Date
Msg-id 426.1108409437@sss.pgh.pa.us
Whole thread Raw
In response to Re: Schema name of function  (Michael Fuhr <mike@fuhr.org>)
List pgsql-hackers
Michael Fuhr <mike@fuhr.org> writes:
> On Mon, Feb 14, 2005 at 11:11:53AM -0500, Tom Lane wrote:
>> In C, it'd be a lot easier (and faster) to do a couple of SearchSysCache
>> calls than to use SPI to get those rows.

> The following appears to work -- does it look right, aside from the
> missing error checking?

>   tuple = SearchSysCache(PROCOID,
>                          ObjectIdGetDatum(fcinfo->flinfo->fn_oid),
>                          0, 0, 0);
>   nsoid = SysCacheGetAttr(PROCOID, tuple,
>                           Anum_pg_proc_pronamespace, &isnull);
>   schemaname = get_namespace_name(nsoid);
>   ReleaseSysCache(tuple);

That would work.  Since pronamespace is one of the fixed non-nullable
columns of pg_proc, you don't really need to use SysCacheGetAttr: you
can just map the C struct onto the tuple and grab the field directly.
nsoid = ((Form_pg_proc) GETSTRUCT(tuple))->pronamespace;

utils/cache/lsyscache.c contains lots of examples of this sort of thing.
(get_namespace_name is one, in fact.)
        regards, tom lane


pgsql-hackers by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: getting oid of function
Next
From: Tom Lane
Date:
Subject: Re: Help me recovering data