Re: BUG #17235: PQsendQuery (with two sql) after PQenterPipelineMode cause ERROR

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Daniel Verite <daniel(at)manitou-mail(dot)org>
Cc: RekGRpth <rekgrpth(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17235: PQsendQuery (with two sql) after PQenterPipelineMode cause ERROR
Date: 2021-10-20 15:01:33
Message-ID: CAKFQuwYrAoY6oF2j8Xc40o4x9v8fBTEet7stTpi_AWeVuBJHNA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Oct 20, 2021 at 2:21 AM Daniel Verite <daniel(at)manitou-mail(dot)org>
wrote:

> PG Bug reporting form wrote:
>
> > I use libpq in C.
> > I call PQsendQuery(conn, "select * from cats; select * from cats") after
> > PQenterPipelineMode.
> > This cause ERROR
> > cannot insert multiple commands into a prepared statement.
> > postgresql client 14
> > postgresql server 13.4
>
>
> In pipeline mode, queries are handled with the extended query protocol
>

This fact is only indirectly mentioned in the documentation:

"While the pipeline API was introduced in PostgreSQL 14, it is a
client-side feature which doesn't require special server support and works
on any server that supports the v3 extended query protocol."

https://www.postgresql.org/docs/current/libpq-pipeline-mode.html

which does not support multiple commands per query.

> This is mentioned in this note in the documentation
> (see
>
> https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
> ):
>

It seems desirable to talk about the multi-command limitation directly in
the libpq chapter of the documentation and only refer to the protocol
documentation for "additional reading". We should not assume the reader of
this material knows that extended protocol implies single command.

More specifically, PQsendQuery is not documented to have the single-command
limitation, nor from what I understand, can a user explicitly make things
such that when used outside of Pipeline mode that the extended query
protocol is used.

It is too late to change now but why did we feel the need to make
PQsendQuery work in Pipeline mode at all? Lacking a decent answer it is
probably worth saying that while PQsendQuery works it behaves like
PQsendQueryParams without any parameters specified. In particular, it does
not allow for multiple commands to be specified in the query.

Combine that with a mention that all interactions with the server are done
using v3 of the extended protocol. Maybe by rewriting the above as:

"While in pipeline mode, communication with the server is done using v3 of
the extended query protocol. This means that the pipeline API can be used
to communicate with all servers that support the protocol. It also means
that it is not possible to include multiple commands in a single query (see
the note in Protocol XRef for details)."

(I don't think the mentioning of v14 adds enough info to keep when we
generally avoid trying to mention versions in our documentation)
David J.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2021-10-20 19:34:31 Re: BUG #17235: PQsendQuery (with two sql) after PQenterPipelineMode cause ERROR
Previous Message Daniel Verite 2021-10-20 09:21:10 Re: BUG #17235: PQsendQuery (with two sql) after PQenterPipelineMode cause ERROR