Wednesday, September 3, 2008

Re: [GENERAL] immutable functions and enumerate type casts in indexes

Martijn van Oosterhout ha scritto:
> On Tue, Sep 02, 2008 at 10:53:03AM +0200, Edoardo Panfili wrote:
>> But i have a little question about parameters of enum_out.
>> Datum enum_out(PG_FUNCTION_ARGS);
>> this is a part of my function
>> -----------------------------------------------------------
>> Datum esterna_nome2(PG_FUNCTION_ARGS){
>> int label;
>> label = enum_out(fcinfo);
>> sprintf(debug,"false enum_out: \"%s\" ",unrolled);
>> elog(LOG, debug);
>> -----------------------------------------------------------
>> but it works only because my enum parameter is the first (and using
>> fcinfo is a little obscure).
>
>
> Look in the fmgr.h header for functions like DirectFunctionCall1 and
> various other ways of calling functions.
>
Now it works! thank you to Martin and Tom.

this is a code fragment:
--------------------------------------------------------------
#include "utils/builtins.h"

PG_FUNCTION_INFO_V1(esterna_nome);
Datum esterna_nome(PG_FUNCTION_ARGS){
Datum datumIbrido = PG_GETARG_DATUM(0);
Datum labelDatum;
char *label;

labelDatum = DirectFunctionCall1(enum_out,datumIbrido);
label = (char *) DatumGetPointer(labelDatum);
if(strcmp(label,("label_constant"))==0){
...
}
...
}
--------------------------------------------------------------
I don't know why but I need <<#include "utils/builtins.h">>

The line "label = (char *) DatumGetPointer(labelDatum);" is essential to
use the information in strcmp() if I use directly labelDatum it does not
works (but it works inside a sprintf(buffer,"%s",labelDatum)).

thank you again
Edoardo


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

No comments: