pgsql: psql: Allow queries terminated by semicolons while in pipeline m

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: psql: Allow queries terminated by semicolons while in pipeline m
Date: 2025-03-19 04:35:12
Message-ID: E1tul96-003CqC-0l@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

psql: Allow queries terminated by semicolons while in pipeline mode

Currently, the only way to pipe queries in an ongoing pipeline (in a
\startpipeline block) is to leverage the meta-commands able to create
extended queries such as \bind, \parse or \bind_named.

While this is good enough for testing the backend with pipelines, it has
been mentioned that it can also be very useful to allow queries
terminated by semicolons to be appended to a pipeline. For example, it
would be possible to migrate existing psql scripts to use pipelines by
just adding a set of \startpipeline and \endpipeline meta-commands,
making such scripts more efficient.

Doing such a change is proving to be simple in psql: queries terminated
by semicolons can be executed through PQsendQueryParams() without any
parameters set when the pipeline mode is active, instead of
PQsendQuery(), the default, like pgbench. \watch is still forbidden
while in a pipeline, as it expects its results to be processed
synchronously.

The large portion of this commit consists in providing more test
coverage, with mixes of extended queries appended in a pipeline by \bind
and friends, and queries terminated by semicolons.

This improvement has been suggested by Daniel Vérité.

Author: Anthonin Bonnefoy <anthonin(dot)bonnefoy(at)datadoghq(dot)com>
Discussion: https://postgr.es/m/d67b9c19-d009-4a50-8020-1a0ea92366a1@manitou-mail.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2cce0fe440fb3f252a7be70a89298168009a2c15

Modified Files
--------------
doc/src/sgml/ref/psql-ref.sgml | 27 ++-
src/bin/psql/command.c | 7 +
src/bin/psql/common.c | 10 +-
src/test/regress/expected/psql_pipeline.out | 252 +++++++++++++++++++++++++---
src/test/regress/sql/psql_pipeline.sql | 110 ++++++++++--
5 files changed, 359 insertions(+), 47 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2025-03-19 06:08:40 pgsql: extension_control_path
Previous Message Thomas Munro 2025-03-19 04:27:35 pgsql: Fix compiler warning for commit 434dbf69.