Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-20 Thread Martijn van Oosterhout
On Wed, Sep 20, 2006 at 11:02:46AM -0400, Jack Orenstein wrote: > >http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/mmgr/README?rev=1.9 > > Thank you, that is a useful document. So let me make sure I understand: > > - My C function is invoked in a MessageContext (which you refer

Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-20 Thread Jack Orenstein
On 9/20/06, Martijn van Oosterhout wrote: On Tue, Sep 19, 2006 at 04:00:43PM -0400, Jack Orenstein wrote: > Can you provide some guidance (or point to some documentation) on how > to manage memory? Is the idea that I should (must?) not pfree > palloc'ed memory from Int64GetDatum, but I should fr

Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-20 Thread Martijn van Oosterhout
On Tue, Sep 19, 2006 at 04:00:43PM -0400, Jack Orenstein wrote: > Can you provide some guidance (or point to some documentation) on how > to manage memory? Is the idea that I should (must?) not pfree > palloc'ed memory from Int64GetDatum, but I should free anything I > allocate myself using palloc?

Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-19 Thread Tom Lane
"Jack Orenstein" <[EMAIL PROTECTED]> writes: > The C extension I'm writing, which uses the SPI, will be called > thousands or millions of times as part of a data conversion -- I do > have to worry about memory leaks. Not if it's called in a short-lived context, which should ordinarily be the case.

Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-19 Thread Jack Orenstein
On 9/19/06, Martijn van Oosterhout wrote: On Tue, Sep 19, 2006 at 01:27:56PM -0400, Jack Orenstein wrote: > On 9/18/06, Jack Orenstein <[EMAIL PROTECTED]> wrote: > >-- Forwarded message -- > >From: Andrew - Supernews <[EMAIL PROTECTED]> > ... > > Jack> I have an int8 that I need

Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-19 Thread Martijn van Oosterhout
On Tue, Sep 19, 2006 at 01:27:56PM -0400, Jack Orenstein wrote: > On 9/18/06, Jack Orenstein <[EMAIL PROTECTED]> wrote: > >-- Forwarded message -- > >From: Andrew - Supernews <[EMAIL PROTECTED]> > ... > > Jack> I have an int8 that I need as a Datum for use with > > Jack> SPI_execute

Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-19 Thread Jack Orenstein
On 9/18/06, Jack Orenstein <[EMAIL PROTECTED]> wrote: -- Forwarded message -- From: Andrew - Supernews <[EMAIL PROTECTED]> ... Jack> I have an int8 that I need as a Datum for use with Jack> SPI_execute_plan. Int64GetDatum(your_variable) which then has to be pfree'd, correct

Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-18 Thread Andrew - Supernews
On 2006-09-18, "Jack Orenstein" <[EMAIL PROTECTED]> wrote: > On 9/14/06, Andrew - Supernews <[EMAIL PROTECTED]> wrote: >> One way: > > Thank you, I hope you can help with some clarifications. > >> >> bytea *my_bytea = (bytea *) palloc(byte_array_len + VARHDRSZ); >> memcpy(VARDATA(my_bytea),

Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-18 Thread Jack Orenstein
On 9/14/06, Andrew - Supernews <[EMAIL PROTECTED]> wrote: On 2006-09-14, "Jack Orenstein" <[EMAIL PROTECTED]> wrote: > I don't think I explained myself clearly. I have a C string (char*, > terminating zero) and a byte array (char*, possibly containing zeros, > and I know the length). I want to ob

Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-14 Thread Andrew - Supernews
On 2006-09-14, "Jack Orenstein" <[EMAIL PROTECTED]> wrote: > I don't think I explained myself clearly. I have a C string (char*, > terminating zero) and a byte array (char*, possibly containing zeros, > and I know the length). I want to obtain Datums wrapping these values > that will be used to bin

Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-14 Thread Jack Orenstein
On 9/13/06, Martijn van Oosterhout wrote: On Tue, Sep 12, 2006 at 09:57:33PM -0400, Jack Orenstein wrote: > ... > 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 I

Re: [GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-12 Thread Martijn van Oosterhout
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 colu

[GENERAL] Initializing Datums for use with SPI_execute_plan

2006-09-12 Thread Jack Orenstein
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 val