Re: version 1 C-Language Functions - Mailing list pgsql-general

From Tom Lane
Subject Re: version 1 C-Language Functions
Date
Msg-id 23494.998863609@sss.pgh.pa.us
Whole thread Raw
In response to RE: version 1 C-Language Functions  ("Gowey, Geoffrey" <ggowey@rxhope.com>)
List pgsql-general
"Gowey, Geoffrey" <ggowey@rxhope.com> writes:
> No example that I have run across illustrates how to convert
> a param entered to be used w/ regular c functions (in this case
> strcat).

I think the technique exhibited in the 7.1 contrib/soundex module is
about the cleanest: use the text type's I/O conversion functions.
Preferably with macros to hide the notational cruft:


#define _textin(str) DatumGetPointer(DirectFunctionCall1(textin, CStringGetDatum(str)))
#define _textout(str) DatumGetPointer(DirectFunctionCall1(textout, PointerGetDatum(str)))

/*
 * SQL function: text_soundex(text) returns text
 */
PG_FUNCTION_INFO_V1(text_soundex);

Datum
text_soundex(PG_FUNCTION_ARGS)
{
    char        outstr[SOUNDEX_LEN + 1];
    char       *arg;

    arg = _textout(PG_GETARG_TEXT_P(0));

    soundex(arg, outstr);

    PG_RETURN_TEXT_P(_textin(outstr));
}

'arg' and 'outstr' are null-terminated strings here.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: problems on solaris 7
Next
From: "Dr. Evil"
Date:
Subject: Re: PL/java?