Unix Technical Forum

SPI_execute (result of a select statement)

This is a discussion on SPI_execute (result of a select statement) within the pgsql Novice forums, part of the PostgreSQL category; --> Hi, While using SPI_execute for a select statement, how do we store the result returned by select statement (say ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:09 PM
Jasbinder Bali
 
Posts: n/a
Default SPI_execute (result of a select statement)

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:09 PM
Jasbinder Bali
 
Posts: n/a
Default Re: [GENERAL] SPI_execute (result of a select statement)

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@svana.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/i...i-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/i...e-support.html
>
> Hope this helps,
> --
> Martijn van Oosterhout <kleptog@svana.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)
>
> iD8DBQFE99P3IB7bNG8LQkwRAgnBAJ9ijj6rGUXYozBviDp5K7 AlYPF4VACfYcS2
> m48ZBwMDuXR9/cY6i+wnqS0=
> =DVar
> -----END PGP SIGNATURE-----
>
>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:50 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com