Обсуждение: Calling V1 function from within the server
Hi, If I define: Datum barcode_checksum(PG_FUNCTION_ARGS) PG_FUNCTION_INFO_V1(barcode_checksum) Datum barcode_checksum(PG_FUNCTION_ARGS) { barcode value; short result; label = (barcode) PG_GETARG_INT32(0); // compute barcode PG_RETURN_INT16(result); } and now want to *use* that function within some other (related) function, how can I invoke it? The intuitive syntax: short foo; barcode label; foo = barcode_checksum(label); gives compiler warnings (pointer from int without cast) as well as SIGSEGV's at run time. The model used for the complex sample data type avoids this issue by creating an "internal" function that is used by other functions -- and *wrapped* in the PG_FUNCTION_INFO_V1 framework under another name (i.e. that name is never used directly in the rest of the code) --don
On Tue, May 02, 2006 at 11:24:34AM -0700, Don Y wrote: > Hi, > > If I define: > > Datum barcode_checksum(PG_FUNCTION_ARGS) > > PG_FUNCTION_INFO_V1(barcode_checksum) <snip> > and now want to *use* that function within some other > (related) function, how can I invoke it? The intuitive You want DirectFunctionCalln or FunctionCalln as defined in fmgr.h Have a nice day, -- Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > From each according to his ability. To each according to his ability to litigate.
Вложения
Martijn van Oosterhout wrote: > On Tue, May 02, 2006 at 11:24:34AM -0700, Don Y wrote: >> Hi, >> >> If I define: >> >> Datum barcode_checksum(PG_FUNCTION_ARGS) >> >> PG_FUNCTION_INFO_V1(barcode_checksum) > > <snip> > >> and now want to *use* that function within some other >> (related) function, how can I invoke it? The intuitive > > You want DirectFunctionCalln or FunctionCalln as defined in fmgr.h Yikes! I *never* would have found that! :-( Thanks! --don