Search Postgresql Archives

Re: Exception Handling in C-Language Functions?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tom Lane wrote:
"Felix E. Klee" <felix.klee@xxxxxxx> writes:

BTW, a more future-proof way of doing what you want:


   VarChar *text = PG_GETARG_VARCHAR_P(0);
   int text_len = VARSIZE(text)-VARHDRSZ;
   char *tmp_text = (char *)malloc(text_len+1);
   if (tmp_text == NULL)
       ; /* What now? */
   strncpy(tmp_text, VARDATA(text), text_len);
   tmp_text[text_len] = '\0';


is to let the varchar output routine do it:

     Datum text_datum = PG_GETARG_DATUM(0);
     char *text;

     text = DatumGetCString(DirectFunctionCall1(varcharout, text_datum));

This avoids assuming that you know the internal representation of
varchar (and if you think that's frozen for eternity, you haven't
been reading the discussions of ramping up our locale support...)

This form of dealing with arguments is interesting to learn about. Is there any documentation of this stuff or do I need to dive into the source?


-greg

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux