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

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

From
Michael Paquier
Date:
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(-)