Re: Trouble with bytea in SPI...

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Cristian Prieto <cristian(at)clickdiario(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Trouble with bytea in SPI...
Date: 2005-09-02 03:05:35
Message-ID: 20050902030535.GA58575@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Matthew Peter 2005-09-02 03:48:51 same size VARCHAR or INT IX faster?
Previous Message Cristian Prieto 2005-09-02 02:23:31 Trouble with bytea in SPI...