Обсуждение: Internal PG functions, how to pass proper parameters?
Hi all
I need a bit assistance. In ../src/backend/utils/adt/tsginidx.c there
is a function called gin_extract_tsquery.
It recieves 5 parameters and I would like to execute it from C code
using my own function. The gin_extract_tsquery relevant part:
Datum
gin_extract_tsquery(PG_FUNCTION_ARGS)
{
TSQuery query = PG_GETARG_TSQUERY(0);
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
/* StrategyNumber strategy = PG_GETARG_UINT16(2); */
bool **ptr_partialmatch = (bool **) PG_GETARG_POINTER(3);
Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4);
Datum *entries = NULL;
bool *partialmatch;
elog(NOTICE,"[%s,%d]","step: ",03);
*nentries = 0;
elog(NOTICE,"[%s,%d]","step: ",04);
.....
}
I created my own simple wrapper function, so I can control the
gin_extract_tsquery directly. Here's the code:
Datum
test(PG_FUNCTION_ARGS)
{
//arguments
HStore<----><------>*hs = PG_GETARG_HS(0);
TSQuery<---><------>tq = PG_GETARG_TSQUERY(1);
Datum<-----><------>*dats;
elog(NOTICE,"[%s,%d]","step: ",01);
//variables
char<------><------>*nentries;
elog(NOTICE,"[%s,%d]","step: ",02);
//operations
nentries = DirectFunctionCall2(gin_extract_tsquery_ljd,
TSQueryGetDatum(tq), dats);
....
}
The above function call is incompleate (only 2 params instead of 5)
but it's not relevant at this point. The issue is that no matter what
I pass (Datum, pointer to Datum, pointer to char, pointer to int32, PG
macros to variables and pointers, etc...) as a 2nd parameter I get an
error when I call my wrapper function from Postgres. It goes well
right until the line before "step: 04" notice in gin_extract_tsquery.
Namely the "*nentries = 0;" line.
What do I need to pass in my wrapper function so it works properly? An
example and short explanation (I just started learning C & PG) would
be greatly appreciated.
Also a related question: Is it possible to launch a function like
gin_extract_query directly from Postgres? I'ts decralation is:
CREATE OR REPLACE FUNCTION gin_extract_tsquery(tsquery, internal,
smallint, internal, internal)
RETURNS internal AS ....
I've tried to find something about "internal" parameters in functions
in manual but failed. If it's possible, what would be a working
example?
Thanks in advance.
On Wed, Apr 07, 2010 at 10:30:35AM +0200, ?ukasz Dejneka wrote: > Hi all > > I need a bit assistance. In ../src/backend/utils/adt/tsginidx.c there > is a function called gin_extract_tsquery. <snip> > The above function call is incompleate (only 2 params instead of 5) > but it's not relevant at this point. The issue is that no matter what > I pass (Datum, pointer to Datum, pointer to char, pointer to int32, PG > macros to variables and pointers, etc...) as a 2nd parameter I get an > error when I call my wrapper function from Postgres. It goes well > right until the line before "step: 04" notice in gin_extract_tsquery. > Namely the "*nentries = 0;" line. This may be silly, but did you declare your function to be a V1 function? > Also a related question: Is it possible to launch a function like > gin_extract_query directly from Postgres? I'ts decralation is: > > CREATE OR REPLACE FUNCTION gin_extract_tsquery(tsquery, internal, > smallint, internal, internal) > RETURNS internal AS .... > > I've tried to find something about "internal" parameters in functions > in manual but failed. If it's possible, what would be a working > example? "internal" usually means a "pointer to something you can't make from SQL". So you might be able to declare the function, but in no way could you actually call it successfully. Have a nice day, -- Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > Patriotism is when love of your own people comes first; nationalism, > when hate for people other than your own comes first. > - Charles de Gaulle
Вложения
2010/4/7 Martijn van Oosterhout <kleptog@svana.org>: > This may be silly, but did you declare your function to be a V1 > function? Yes, it is properly declared V1 function. The parameter is a pointer so as I understand the concept it is used to access some other processed data than the function result. But still can't get it right... >> Also a related question: Is it possible to launch a function like >> gin_extract_query directly from Postgres? I'ts decralation is: >> >> CREATE OR REPLACE FUNCTION gin_extract_tsquery(tsquery, internal, >> smallint, internal, internal) >> RETURNS internal AS .... >> >> I've tried to find something about "internal" parameters in functions >> in manual but failed. If it's possible, what would be a working >> example? > > "internal" usually means a "pointer to something you can't make from > SQL". So you might be able to declare the function, but in no way could > you actually call it successfully. Thank you for the answer !