Tom Lane wrote:
> "Felix E. Klee" <felix.klee@inka.de> writes:
>
> BTW, a more future-proof way of doing what you want:
>
>
>> VarChar *text = PG_GETARG_VARCHAR_P(0);
>> int text_len = VARSIZE(text)-VARHDRSZ;
>> char *tmp_text = (char *)malloc(text_len+1);
>> if (tmp_text == NULL)
>> ; /* What now? */
>> strncpy(tmp_text, VARDATA(text), text_len);
>> tmp_text[text_len] = '\0';
>
>
> is to let the varchar output routine do it:
>
> Datum text_datum = PG_GETARG_DATUM(0);
> char *text;
>
> text = DatumGetCString(DirectFunctionCall1(varcharout, text_datum));
>
> This avoids assuming that you know the internal representation of
> varchar (and if you think that's frozen for eternity, you haven't
> been reading the discussions of ramping up our locale support...)
This form of dealing with arguments is interesting to learn about. Is
there any documentation of this stuff or do I need to dive into the source?
-greg