Improve handling of empty query results in BackgroundPsql::query()
authorMichael Paquier <[email protected]>
Thu, 7 Nov 2024 03:11:27 +0000 (12:11 +0900)
committerMichael Paquier <[email protected]>
Thu, 7 Nov 2024 03:11:27 +0000 (12:11 +0900)
commit70291a3c66eca599fd9f59f7f6051432b2020f4b
tree1afba01ca50f07f9e8056fd2a938a5f79b2158c2
parentf638aafd1ea8505750ca9546e0e0b2e4cf31027d
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
src/test/perl/PostgreSQL/Test/BackgroundPsql.pm
src/test/recovery/t/037_invalid_database.pl