Search Postgresql Archives

Re: Initializing Datums for use with SPI_execute_plan

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

 



On Tue, Sep 12, 2006 at 09:57:33PM -0400, Jack Orenstein wrote:
> 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?

Yes, need to use the *GetDatum functions.

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

CStringGetDatum will get you something of the right format for cstring,
if you want varchar, you need to have an object of "VarChar*" first.

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

Similarly you should use "bytea*" here. Then you can 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.

Pretty much.

Have a nice day,
-- 
Martijn van Oosterhout   <kleptog@xxxxxxxxx>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment: signature.asc
Description: Digital signature


[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