Re: [HACKERS] return varchar from C function

2007-02-18 Thread Enrico
Thanks for all your answers, I begin to study. Enrico -- Enrico <[EMAIL PROTECTED]> ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [HACKERS] return varchar from C function

2007-02-18 Thread Pavel Stehule
"Pavel Stehule" <[EMAIL PROTECTED]> 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

Re: [HACKERS] return varchar from C function

2007-02-18 Thread Martijn van Oosterhout
On Sun, Feb 18, 2007 at 12:56:08PM -0500, [EMAIL PROTECTED] wrote: > Hi, > just for fun, I wrote a little postgresql contrib, > who has a C function called myfun inside it. > The function myfun returns a value , now I return > a cstring type value, and it works fine if > I run from psql shell: Y

Re: [HACKERS] return varchar from C function

2007-02-18 Thread Gregory Stark
"Pavel Stehule" <[EMAIL PROTECTED]> 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 dat

Re: [HACKERS] return varchar from C function

2007-02-18 Thread Pavel Stehule
Hello cstring is clasic c (zero terminated) string and is used only in some PostgreSQL functions. This type isn't compatible with text and you have to explicit cast trick with textin function. root=# select textin(('abc'::cstring)); textin abc (1 row) Standard is using VARLENA types