Re: return varchar from C function

From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: stark(at)enterprisedb(dot)com
Cc: scotty(at)linuxtime(dot)it, pgsql-hackers(at)postgresql(dot)org
Subject: Re: return varchar from C function
Date: 2007-02-18 15:38:16
Message-ID: BAY20-F2DC691586B7BF38100A59F98B0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


>"Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
>
> >
> > Datum *const_fce(PG_FUNCTION_ARGS)
> > {
> > text *txt = palloc(5 + VARHDRSZ);
> > memcpy(VARDATA(txt), "pavel", 5);
> > VARATT_SIZE(txt) = 5 + VARHDRSZ;
> >
> > PG_RETURN_TEXT_P(txt);
> > }
>
>Much better practice is to use the input function of the data type you want
>to
>convert to:
>
>{
> text *txt = DatumGetTextP(DirectFunctionCall1(textin,
>CStringGetDatum("pavel")));
> PG_RETURN_TEXT_P(txt);
>}
>

Generally we want to do something with text value (concat, trim, ..) and
then call textin isn't practic. Respective, for bussness processes
implemented in C is textin and similar functions right. For string toolkit
is better direct work with VARLENA struct.

Regards and thank you note

Pavel

_________________________________________________________________
Emotikony a pozadi programu MSN Messenger ozivi vasi konverzaci.
http://messenger.msn.cz/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Knut P. Lehre 2007-02-18 16:21:02 FETCH from scroll cursor does not return count in libpq PQcmdStatus
Previous Message Martijn van Oosterhout 2007-02-18 15:08:55 Re: return varchar from C function