Re: SPI_execute (result of a select statement)

Lists: pgsql-generalpgsql-novice
From: "Jasbinder Bali" <jsbali(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org
Subject: SPI_execute (result of a select statement)
Date: 2006-09-01 06:24:32
Message-ID: a47902760608312324yc7b1d2fyb90a60fb920dcb03@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-novice

Hi,

While using SPI_execute for a select statement, how do we store the result
returned by select statement (say a C variable)?
SPI_execute returns different values for success or failure only as per the
postgres manual.

Thanks,
Jas


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Jasbinder Bali <jsbali(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org
Subject: Re: SPI_execute (result of a select statement)
Date: 2006-09-01 06:32:23
Message-ID: 20060901063223.GB12644@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-novice

On Fri, Sep 01, 2006 at 02:24:32AM -0400, Jasbinder Bali wrote:
> Hi,
>
> While using SPI_execute for a select statement, how do we store the result
> returned by select statement (say a C variable)?
> SPI_execute returns different values for success or failure only as per the
> postgres manual.

Did you read the whole page?

http://www.postgresql.org/docs/8.1/interactive/spi-spi-execute.html

Especially the bit where it says:

If the return value of the function is SPI_OK_SELECT then you may use
the global pointer SPITupleTable *SPI_tuptable to access the result
rows.

From there you can get the data. There's also the helper functions like
SPI_getvalue().

http://www.postgresql.org/docs/8.1/interactive/spi-interface-support.html

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


From: "Jasbinder Bali" <jsbali(at)gmail(dot)com>
To: "Martijn van Oosterhout" <kleptog(at)svana(dot)org>, pgsql-general(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org
Subject: Re: SPI_execute (result of a select statement)
Date: 2006-09-01 07:41:12
Message-ID: a47902760609010041p5e7959eay40fa3001c93b9bc7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-novice

The structure SPITupleTable is defined thus:

typedef struct
{
MemoryContext tuptabcxt; /* memory context of result table */
uint32 alloced; /* number of alloced vals */
uint32 free; /* number of free vals */
TupleDesc tupdesc; /* row descriptor */
HeapTuple *vals; /* rows */
} SPITupleTable;

If the select query returns 10 rows (say),
how to access the result of each row separately?

Can you please help me with the syntax of the same?

Regards,

~Jas

On 9/1/06, Martijn van Oosterhout <kleptog(at)svana(dot)org> wrote:
>
> On Fri, Sep 01, 2006 at 02:24:32AM -0400, Jasbinder Bali wrote:
> > Hi,
> >
> > While using SPI_execute for a select statement, how do we store the
> result
> > returned by select statement (say a C variable)?
> > SPI_execute returns different values for success or failure only as per
> the
> > postgres manual.
>
> Did you read the whole page?
>
> http://www.postgresql.org/docs/8.1/interactive/spi-spi-execute.html
>
> Especially the bit where it says:
>
> If the return value of the function is SPI_OK_SELECT then you may use
> the global pointer SPITupleTable *SPI_tuptable to access the result
> rows.
>
> From there you can get the data. There's also the helper functions like
> SPI_getvalue().
>
> http://www.postgresql.org/docs/8.1/interactive/spi-interface-support.html
>
> Hope this helps,
> --
> Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> > From each according to his ability. To each according to his ability to
> litigate.
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.1 (GNU/Linux)
>
> iD8DBQFE99P3IB7bNG8LQkwRAgnBAJ9ijj6rGUXYozBviDp5K7AlYPF4VACfYcS2
> m48ZBwMDuXR9/cY6i+wnqS0=
> =DVar
> -----END PGP SIGNATURE-----
>
>
>


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Jasbinder Bali <jsbali(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org
Subject: Re: SPI_execute (result of a select statement)
Date: 2006-09-01 07:52:43
Message-ID: 20060901075243.GG12644@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-novice

On Fri, Sep 01, 2006 at 03:41:12AM -0400, Jasbinder Bali wrote:
> The structure SPITupleTable is defined thus:

<snip>

> If the select query returns 10 rows (say),
> how to access the result of each row separately?

<snip>

Read this:

> >http://www.postgresql.org/docs/8.1/interactive/spi-interface-support.html

I would say that the example should clear up most of your questions:

http://www.postgresql.org/docs/8.1/interactive/spi-examples.html

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.