Re: Trouble with bytea in SPI... - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Trouble with bytea in SPI...
Date
Msg-id 20050902030535.GA58575@winnie.fuhr.org
Whole thread Raw
In response to Trouble with bytea in SPI...  ("Cristian Prieto" <cristian@clickdiario.com>)
Responses Re: Trouble with bytea in SPI...
List pgsql-general
On Thu, Sep 01, 2005 at 08:23:31PM -0600, Cristian Prieto wrote:
> Hello, I've been working just a little with SPI in a few stored
> functions, this is a model of my SP:

Please post a real example instead of a "model."  The code you
posted fails to compile, with errors and warnings like the following:

spitest.c: In function `myspi':
spitest.c:18: `ret' undeclared (first use in this function)
spitest.c:18: (Each undeclared identifier is reported only once
spitest.c:18: for each function it appears in.)
spitest.c:39: warning: passing arg 2 of `SPI_execp' from incompatible pointer type
spitest.c:41: warning: implicit declaration of function `SPI_finnish'
spitest.c:16: warning: unused variable `res'

Since what you posted doesn't compile, it can't be what you're
really doing; that means we have to guess at what the real code
looks like.  It would be easier to help if we could see the real
thing so we don't have to guess.

>     // This is where the SP and the connection dies!
>     ret = SPI_execp(plan, val, NULL, 1);

val is a bytea * but the second argument to SPI_execp() is a Datum *
(the compiler warning hints that something's wrong here).  Try
something like this:

    Datum  values[1];

    values[0] = PointerGetDatum(val);
    ret = SPI_execp(plan, values, NULL, 1);

That works for me in simple tests.  If anybody sees a problem with
it then please make corrections.

--
Michael Fuhr

pgsql-general by date:

Previous
From: "Cristian Prieto"
Date:
Subject: Trouble with bytea in SPI...
Next
From: Matthew Peter
Date:
Subject: same size VARCHAR or INT IX faster?