pgsql: Improve handling of empty query results in BackgroundPsql::query

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improve handling of empty query results in BackgroundPsql::query
Date: 2024-11-07 03:13:11
Message-ID: E1t8sxL-000ZAT-4M@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve handling of empty query results in BackgroundPsql::query()

A newline is not added at the end of an empty query result, causing the
banner of the hardcoded \echo to not be discarded. This would reflect
on scripts that expect an empty result by showing the "QUERY_SEPARATOR"
in the output returned back to the caller, which was confusing.

This commit changes BackgroundPsql::query() so as empty results are able
to work correctly, making the first newline before the banner optional,
bringing more flexibility.

Note that this change affects 037_invalid_database.pl, where three
queries generated an empty result, with the script relying on the data
from the hardcoded banner to exist in the expected output. These
queries are changed to use query_safe(), leading to a simpler script.

The author has also proposed a test in a different patch where empty
results would exist when using BackgroundPsql.

Author: Jacob Champion
Reviewed-by: Andrew Dunstan, Michael Paquier
Discussion: https://postgr.es/m/CAOYmi+=60deN20WDyCoHCiecgivJxr=98s7s7-C8SkXwrCfHXg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/70291a3c66eca599fd9f59f7f6051432b2020f4b

Modified Files
--------------
src/test/perl/PostgreSQL/Test/BackgroundPsql.pm | 6 ++++--
src/test/recovery/t/037_invalid_database.pl | 14 +++++---------
2 files changed, 9 insertions(+), 11 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2024-11-07 03:39:47 pgsql: Replicate generated columns when 'publish_generated_columns' is
Previous Message Jeff Davis 2024-11-06 22:49:05 pgsql: Fix lc_collate_is_c() when LC_COLLATE != LC_CTYPE.