Search Postgresql Archives

Initializing Datums for use with SPI_execute_plan

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

 



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


[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