Обсуждение: about call-convention in PostgreSQL programming

Поиск
Список
Период
Сортировка

about call-convention in PostgreSQL programming

От
"Seung Hyun Jeong"
Дата:
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.







Re: about call-convention in PostgreSQL programming

От
Tom Lane
Дата:
"Seung Hyun Jeong" <jeongs@cs.man.ac.uk> writes:
> Relation open_gist(PG_FUNCTION_ARGS)
> {
>    char *index_name = (char *) PG_GETARG_POINTER(0);

You didn't say what datatype your function is declared to accept ...
but there is no Postgres datatype that is identical to a C string.
You have some conversion work to do if you want to, say, produce
a C string from a "text" input.
        regards, tom lane