Re: version 1 C-Language Functions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Gowey, Geoffrey" <ggowey(at)rxhope(dot)com>
Cc: "'Francesco Casadei'" <f_casadei(at)libero(dot)it>, "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: version 1 C-Language Functions
Date: 2001-08-26 22:06:49
Message-ID: 23494.998863609@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Gowey, Geoffrey" <ggowey(at)rxhope(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dr. Evil 2001-08-26 23:51:35 Re: PL/java?
Previous Message Tom Lane 2001-08-26 21:30:24 Re: problems on solaris 7