Skip site navigation (1) Skip section navigation (2)

PQexecPrepared with cursor to fetch single results

From: Maurizio Oristanio <maurizio(dot)oristanio(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: PQexecPrepared with cursor to fetch single results
Date: 2008-04-28 12:21:49
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
if you need a scrollable cursor for a prepared statement (to fetch
single rows from huge result sets)
while still being able to execute statements on the same connection
you can do it this way:

PGresult* res = PQprepare( con, "statement1", "declare cu1 scroll
cursor with hold for select * from table where col1=$1", 0, NULL );
PGresult* res2 = PQdescribePrepared( con, "statement1" );
//now use PQnparams and PQnparamtype to determine parameter
//and set paramCount, paramValues and paramLength accordingly
PGresult* res3 = PQexecPrepared( con, "statement1", paramCount,
paramValues, paramLength, paramFormat, 0 );
PGresult* res4 = PQexec( con, "fetch forward 100 from cu1" ); //to
receive 100 rows from the server
//now with PQnfields, PQftype and PQfname and PQgetvalue access the
result - and other queries can be executed on the same connection

pgsql-hackers by date

Next:From: Magnus HaganderDate: 2008-04-28 14:00:34
Subject: Re: pgstat SRF?
Previous:From: Tom DunstanDate: 2008-04-28 11:49:32
Subject: Re: Re: [COMMITTERS] pgsql: Update: < * Allow adding enumerated values to an existing

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group