Re: return varchar from C function

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(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:01:49
Message-ID: 874ppjqzky.fsf@stark.xeocode.com
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);
}

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Martijn van Oosterhout 2007-02-18 15:08:55 Re: return varchar from C function
Previous Message Pavel Stehule 2007-02-18 14:54:54 Re: return varchar from C function