From: Peter Eisentraut Date: Fri, 24 Mar 2017 12:41:32 +0000 (-0400) Subject: Handle empty result set in libpqrcv_exec X-Git-Tag: REL_10_BETA1~532 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8398c836892fde2b99139cc4711e57b7e59582b6;p=postgresql 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 --- 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",