pgbackrest.git / summary / log / commit / refs
commit d5cefb7290c34c64a2b9aa89ff04a718df4ec18b
Author: David Steele <david@pgmasters.net>
Commit: GitHub <noreply@github.com>
Date: Wed Jan 29 18:48:26 2025 +0000
Fix error reporting for queries with no results.
If a query that expected no results returned an error then it would incorrectly report that no results were expected because the error was interpreted as a result.
Switch the order of the checks so that an error is reported instead and add a test to prevent regression.
doc/xml/release/2025/2.55.0.xml | 12 ++++++++++++
doc/xml/release/contributor.xml | 4 ++++
src/postgres/client.c | 9 +++++----
test/src/module/postgres/clientTest.c | 26 ++++++++++++++++++++++++++
4 files changed, 47 insertions(+), 4 deletions(-)
diff --git a/doc/xml/release/2025/2.55.0.xml b/doc/xml/release/2025/2.55.0.xml
index 5968f69ea..184ae7c55 100644
--- a/doc/xml/release/2025/2.55.0.xml
+++ b/doc/xml/release/2025/2.55.0.xml
@@ -11,6 +11,18 @@
<p>Do not set <br-option>recovery_target_timeline=current</br-option> for PostgreSQL &lt; 12.</p>
</release-item>
+
+ <release-item>
+ <github-pull-request id="2539"/>
+
+ <release-item-contributor-list>
+ <release-item-ideator id="susantha.bathige"/>
+ <release-item-contributor id="david.steele"/>
+ <release-item-reviewer id="stefan.fercot"/>
+ </release-item-contributor-list>
+
+ <p>Fix error reporting for queries with no results.</p>
+ </release-item>
</release-bug-list>
<release-improvement-list>
diff --git a/doc/xml/release/contributor.xml b/doc/xml/release/contributor.xml
index 4afc262d3..9a8e1515c 100644
--- a/doc/xml/release/contributor.xml
+++ b/doc/xml/release/contributor.xml
@@ -1000,6 +1000,10 @@
<contributor-id type="github">sfrost</contributor-id>
</contributor>
+<contributor id="susantha.bathige">
+ <contributor-name-display>Susantha Bathige</contributor-name-display>
+</contributor>
+
<contributor id="t.anastacio">
<contributor-name-display>T.Anastacio</contributor-name-display>
<contributor-id type="github">Tiago-Anastacio</contributor-id>
diff --git a/src/postgres/client.c b/src/postgres/client.c
index 0addaf6d4..fa7a59c0f 100644
--- a/src/postgres/client.c
+++ b/src/postgres/client.c
@@ -243,10 +243,7 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
}
else
{
- if (resultType == pgClientQueryResultNone)
- THROW_FMT(DbQueryError, "no result expected from '%s'", strZ(query));
-
- // Expect some rows to be returned
+ // If no tuples then the result is an error
if (resultStatus != PGRES_TUPLES_OK)
{
THROW_FMT(
@@ -254,6 +251,10 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
strZ(strTrim(strNewZ(PQresultErrorMessage(pgResult)))));
}
+ // Expect some rows to be returned
+ if (resultType == pgClientQueryResultNone)
+ THROW_FMT(DbQueryError, "no result expected from '%s'", strZ(query));
+
// Fetch row and column values
PackWrite *const pack = pckWriteNewP();
diff --git a/test/src/module/postgres/clientTest.c b/test/src/module/postgres/clientTest.c
index b0a08af65..4a926ab03 100644
--- a/test/src/module/postgres/clientTest.c
+++ b/test/src/module/postgres/clientTest.c
@@ -143,6 +143,32 @@ testRun(void)
#undef TEST_PQ_ERROR
#undef TEST_QUERY
+ // -------------------------------------------------------------------------------------------------------------------------
+ TEST_TITLE("unable to execute query that returns no results");
+
+ #define TEST_PQ_ERROR \
+ "ERROR: must be superuser or have privileges of pg_checkpoint to do CHECKPOINT"
+ #define TEST_QUERY "checkpoint"
+
+#ifndef HARNESS_PQ_REAL
+ HRN_PQ_SCRIPT_SET(
+ {.function = HRN_PQ_SENDQUERY, .param = "[\"" TEST_QUERY "\"]", .resultInt = 1},
+ {.function = HRN_PQ_CONSUMEINPUT},
+ {.function = HRN_PQ_ISBUSY},
+ {.function = HRN_PQ_GETRESULT},
+ {.function = HRN_PQ_RESULTSTATUS, .resultInt = PGRES_FATAL_ERROR},
+ {.function = HRN_PQ_RESULTERRORMESSAGE, .resultZ = TEST_PQ_ERROR},
+ {.function = HRN_PQ_CLEAR},
+ {.function = HRN_PQ_GETRESULT, .resultNull = true});
+#endif
+
+ TEST_ERROR(
+ pgClientQuery(client, STRDEF(TEST_QUERY), pgClientQueryResultNone), DbQueryError,
+ "unable to execute query '" TEST_QUERY "': " TEST_PQ_ERROR);
+
+ #undef TEST_PQ_ERROR
+ #undef TEST_QUERY
+
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("query timeout");
[parent: d50b01b4852d]