From 8398c836892fde2b99139cc4711e57b7e59582b6 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 24 Mar 2017 08:41:32 -0400 Subject: [PATCH] Handle empty result set in libpqrcv_exec Always return tupleslot and tupledesc from libpqrcv_exec. This avoids requiring callers to handle that separately. Author: Petr Jelinek Reported-by: Michael Banck --- .../replication/libpqwalreceiver/libpqwalreceiver.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c index 4dd8eef1f9..9d7bb25d39 100644 --- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c +++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c @@ -803,10 +803,6 @@ libpqrcv_processTuples(PGresult *pgres, WalRcvExecResult *walres, MemoryContext rowcontext; MemoryContext oldcontext; - /* No point in doing anything here if there were no tuples returned. */ - if (PQntuples(pgres) == 0) - return; - /* Make sure we got expected number of fields. */ if (nfields != nRetTypes) ereport(ERROR, @@ -824,6 +820,10 @@ libpqrcv_processTuples(PGresult *pgres, WalRcvExecResult *walres, PQfname(pgres, coln), retTypes[coln], -1, 0); attinmeta = TupleDescGetAttInMetadata(walres->tupledesc); + /* No point in doing more here if there were no tuples returned. */ + if (PQntuples(pgres) == 0) + return; + /* Create temporary context for local allocations. */ rowcontext = AllocSetContextCreate(CurrentMemoryContext, "libpqrcv query result context",