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

Re: libpq and multiple selects in a single query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tim Hart <tjhart(at)mac(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: libpq and multiple selects in a single query
Date: 2002-12-28 21:23:27
Message-ID: 4676.1041110607@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-interfaces
Tim Hart <tjhart(at)mac(dot)com> writes:
> Would it be worth the effort to add to and/or modify the libpq API so 
> that multiple selects could be sent to the server in a single request 
> and response?

You can do it already.  See PQsendQuery and PQgetResult.
http://www.ca.postgresql.org/users-lounge/docs/7.3/postgres/libpq-async.html
mentions this specifically:

     PQexec can return only one PGresult structure. If the submitted
     command string contains multiple SQL
     commands, all but the last PGresult are discarded by PQexec.

There is a lot of other cruft here to allow nonblocking interaction with
the server, but if all you care about is multiple commands sent in a
single string, you only need

	PQsendQuery(...);
	while ((res = PQgetResult(...)))
	{
		process result;
		PQclear(res);
	}

			regards, tom lane

In response to

pgsql-interfaces by date

Next:From: Stefan ReuschkeDate: 2002-12-29 21:13:19
Subject: compiling 7.2.3 with tcl -- tcl.h
Previous:From: "."Date: 2002-12-28 09:33:45
Subject: Re: libpq and multiple selects in a single query

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