Problems converting between C string and Datum

Поиск
Список
Период
Сортировка
От Jack Orenstein
Тема Problems converting between C string and Datum
Дата
Msg-id 7ecd811f0609200819n1eba1dc1i87073c0ef1c1719e@mail.gmail.com
обсуждение исходный текст
Ответы Re: Problems converting between C string and Datum  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Problems converting between C string and Datum  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
Thanks for all your help with the memory management problems. Next
problem: I'm having problems converting from a char* to a Datum and back
again.

I have a char* which I need as a Datum, for use with a plan returned
from SPI_prepare, so I'm doing this:

    char* string;
    Datum d;
    ...
    d = DirectFunctionCall1(textin, CStringGetDatum(string));
    ...
    ereport(WARNING, (errmsg("string: %s",

DatumGetCString(DirectFunctionCall1(textout, d)))));

(The ereport is for debugging -- my code then proceeds to call
SPI_execute_plan.)

This crashes doing the ereport:

    psql:test.sql:23: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

So my questions are:

1) Is this code the way to convert char* to Datum and back again?

    DirectFunctionCall1(textin, CStringGetDatum(string))
    ...
    DatumGetCString(DirectFunctionCall1(textout, d))

I've put this code together based on examples I've found on the web
and in the postgres source.

2) Is there some neater way to generate debug output than ereport(WARNING, ...)?
The output is quite verbose, e.g.

    psql:test.sql:23: WARNING:  MY DEBUG OUTPUT
    CONTEXT:  SQL statement "insert into log select insert_ifs(  $1 ,
$2 ,  $3 ,  $4 ,  $5 ,  $6 ,  $7 )"
    PL/pgSQL function "regress" line 5 at SQL statement

for each line of output.


Jack Orenstein

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: pg_dump output containing CREATE TYPE does not restore with psql
Следующее
От: Jeff Davis
Дата:
Сообщение: 8.2: select from an INSERT returning?