Handle empty result set in libpqrcv_exec
authorPeter Eisentraut <[email protected]>
Fri, 24 Mar 2017 12:41:32 +0000 (08:41 -0400)
committerPeter Eisentraut <[email protected]>
Fri, 24 Mar 2017 12:41:32 +0000 (08:41 -0400)
Always return tupleslot and tupledesc from libpqrcv_exec.  This avoids
requiring callers to handle that separately.

Author: Petr Jelinek <[email protected]>
Reported-by: Michael Banck <[email protected]>
src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

index 4dd8eef1f92d6cf8bcb611145cd49d241e8010ec..9d7bb25d3976a305cc940b288a391b26851cd803 100644 (file)
@@ -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",