Thread: Accessing fields past CATALOG_VARLEN

Accessing fields past CATALOG_VARLEN

From
Ed Behn
Date:
I'm trying to write a C-language function to be compiled into a shared module to be loaded by Postgres. In it, I have the OID of a function and I need to get information from the pg_proc table. 

So far, I have:

HeapTuple procTuple;
Form_pg_proc procStruct;

procTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid));
if(!HeapTupleIsValid(procTuple))
    ereport(ERROR, errmsg("cache lookup failed for function %u.", funcoid));
 
procStruct = (Form_pg_proc) GETSTRUCT(procTuple);

I can get fields like procStruct->prokind and procStruct->proretset.

However, I get a compiler error when I try to access procStruct->proargmodes. I know that this is because this field is in the CATALOG_VARLEN block which makes it invisible to the compiler. 

What is the proper way to get this field? 

       -Ed




Re: Accessing fields past CATALOG_VARLEN

From
Chapman Flack
Date:
On 01/03/22 17:23, Ed Behn wrote:
> However, I get a compiler error when I try to access procStruct->proargmodes.
> I know that this is because this field is in the CATALOG_VARLEN block which
> makes it invisible to the compiler.
> 
> What is the proper way to get this field?

You can use SysCacheGetAttr with the attribute number. It knows all the
magic needed to find the right offset, possibly decompress, etc.

Regards,
-Chap



Re: Accessing fields past CATALOG_VARLEN

From
Tom Lane
Date:
Ed Behn <ed@behn.us> writes:
> I can get fields like procStruct->prokind and procStruct->proretset.
> However, I get a compiler error when I try to access procStruct->proargmodes.
> I know that this is because this field is in the CATALOG_VARLEN block which
> makes it invisible to the compiler.
> What is the proper way to get this field?

SysCacheGetAttr().  There are examples all over the tree, but
one that's specific to proargmodes (and also illustrates the
best practices for deciphering its value) is in
parser/analyze.c's transformCallStmt().

You should also ask yourself if you really *need* to examine
proargmodes for yourself, or if there's a utility function
somewhere that will compute what you need to know.

            regards, tom lane