diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c index 96ea74f118..6329756f3a 100644 --- a/src/backend/tcop/pquery.c +++ b/src/backend/tcop/pquery.c @@ -878,6 +878,11 @@ PortalRunSelect(Portal portal, */ if (queryDesc) queryDesc->dest = dest; + else if (!portal->holdStore) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("cursor can not scan"), + errhint("Not ready held data, to scan."))); /* * Determine which direction to go in, and check to see if we're already @@ -898,11 +903,12 @@ PortalRunSelect(Portal portal, count = 0; /* don't pass negative count to executor */ } else + { direction = ForwardScanDirection; - - /* In the executor, zero count processes all rows */ - if (count == FETCH_ALL) - count = 0; + /* In the executor, zero count processes all rows */ + if (count == FETCH_ALL) + count = 0; + } if (portal->holdStore) nprocessed = RunFromStore(portal, direction, (uint64) count, dest); @@ -938,11 +944,12 @@ PortalRunSelect(Portal portal, count = 0; /* don't pass negative count to executor */ } else + { direction = BackwardScanDirection; - - /* In the executor, zero count processes all rows */ - if (count == FETCH_ALL) - count = 0; + /* In the executor, zero count processes all rows */ + if (count == FETCH_ALL) + count = 0; + } if (portal->holdStore) nprocessed = RunFromStore(portal, direction, (uint64) count, dest);