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 like text, varchar, ... You can find info in PostgreSQL FAQ. These types are similar Pascal string -> first four bytes cary length and next bytes are data without spec. ending symbol. http://www.varlena.com/GeneralBits/68.php

using text type in C function is simple:

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);
}

please look to source code my orafce contrib module (you can find it on pgfoundry).

Regards
Pavel Stehule

_________________________________________________________________
Najdete si svou lasku a nove pratele na Match.com. http://www.msn.cz/


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
      choose an index scan if your joining column's datatypes do not
      match

Reply via email to