Initializing Datums for use with SPI_execute_plan

Поиск
Список
Период
Сортировка
От Jack Orenstein
Тема Initializing Datums for use with SPI_execute_plan
Дата
Msg-id 7ecd811f0609121857m40db2e70hdb7f121549e286f@mail.gmail.com
обсуждение исходный текст
Ответы Re: Initializing Datums for use with SPI_execute_plan  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
I am trying to write a postgresql extension in C, which uses
SPI_prepare and SPI_execute_plan. What I want to do is to create a
prepared INSERT statement, bind some int, bigint, varchar and
bytea values, and then execute the INSERT.

I'm stuck on how to bind the values. The problem is that the values
being bound are not present as Datums. I don't get them as function
parameters, or from a table. I have data encoded, in a proprietary
format in one bytea column of a table. My function decodes the bytea
yielding the values that I need to bind to the INSERT statement.

int, bigint: From looking at postgres.h, I realize that Datum is an
unsigned long. I'm guessing that I should just be able to assign Datums
carrying ints or bigints, e.g. using Int32GetDatum to cast the int to
a Datum. Is that correct?

varchar: I have a zero-terminated string that I need to turn into a
Datum. Is CStringGetDatum the right thing to use?

bytea: I have an unsigned char* (not zero-terminated). Can I use
PointerGetDatum?

For the varchar and bytea cases, I assume that I simply pfree the
palloc'ed data as usual, after the SPI_execute_plan call.

Jack Orenstein

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

Предыдущее
От: "J S B"
Дата:
Сообщение: berkley sockets
Следующее
От: Francisco Reyes
Дата:
Сообщение: Re: Superuser lost access to particular database