Re: Is PQgetResult() guaranteed to return the whole SQL command result?

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Arseny Sher <a(dot)sher(at)postgrespro(dot)ru>, pgsql-docs(at)postgresql(dot)org
Subject: Re: Is PQgetResult() guaranteed to return the whole SQL command result?
Date: 2017-12-13 17:20:33
Message-ID: f2f8adbf-d6e9-4e49-06b6-d1765a101ccf@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On 12/13/17 08:50, Arseny Sher wrote:
> I wonder is it guaranteed that one PQgetResult() call returns result for
> the whole one statement (SQL command) in usual (not SingleRow) mode?
> For instance, if I run PQsendQuery with query consisting of two
> statements (separated by semicolons), is possible to have three or more
> PQgetResult calls returning data? I guess not, but it seems to be not
> clear from the docs.
>
> PQgetResult description says:
>
> Waits for the next result from a prior call...
>
> Does one "result" here correspond to one statement?

If you PQsendQuery() a string consisting of multiple statements (e.g.,
"SELECT 1; SELECT 2;"), you will have to call PQgetResult() twice to get
two result sets. The third call will return NULL indicating that there
are not more result sets.

Are you asking whether it is possible that the results for the two
statements might be split across more than two libpq result sets? That
is not possible.

But there is a possible future feature that a single command could
produce more than one result set. So it is not necessarily the case
that the number of statements equals the number of result sets. But the
relationship should always be deterministic.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Arseny Sher 2017-12-14 05:31:45 Re: Is PQgetResult() guaranteed to return the whole SQL command result?
Previous Message Arseny Sher 2017-12-13 13:50:59 Is PQgetResult() guaranteed to return the whole SQL command result?