Re: return varchar from C function
От | Pavel Stehule |
---|---|
Тема | Re: return varchar from C function |
Дата | |
Msg-id | BAY20-F2DC691586B7BF38100A59F98B0@phx.gbl обсуждение исходный текст |
Ответ на | Re: return varchar from C function (Gregory Stark <stark@enterprisedb.com>) |
Список | pgsql-hackers |
>"Pavel Stehule" <pavel.stehule@hotmail.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/
В списке pgsql-hackers по дате отправления: