Hi,
I am learning PostgreSQL programming, but it is still so difficult.
Let me ask some of you who have better experience than me- in fact, I am a
novice!
I am trying to access index structure by using user-defined functions, and
as the first step,
I wrote the following simple user-defined functions.
PG_FUNCTION_INFO_V1(open_gist);
PG_FUNCTION_INFO_V1(close_gist);
/***************************************************************************
/
Relation open_gist(PG_FUNCTION_ARGS)
{ char *index_name = (char *) PG_GETARG_POINTER(0); elog(NOTICE, "%s\n", index_name); return
index_openr(index_name);
}
/***************************************************************************
/
void close_gist(PG_FUNCTION_ARGS)
{ Relation index_relation = (Relation) PG_GETARG_POINTER(0); index_close(index_relation);
}
The problem is that I cannot understand the PostgreSQL's call-convention,
though I have go through
the header file "fmgr.h".
I tried to follow some examples as above, but it won't work.
I just got a garbage string on screen printed by elog(), when I execute
"select open_gist('myindex');".
So, I tried to pass index name directly to index_openr(), that is
index_openr("myindex"), then there was no problem.
I think it is the problem about how to pass arguments.
And do you think I can execute the above functions like this:
select close_gist(open_gist('myindex'));
My question is whether the return data from open_gist() can be passed to
close_gist() or not.
I mean, because data type "Relation" is just internal data type, not the
base data type of PostgreSQL,
I am worried about the representation of return data type.
Do I need to register "Relation" as user-defined data type as well?
(When I create the two functions, I declared input and output data types to
be "opaque".)
Could you advise me anything about that?
Cheers.