diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-02-10 20:36:28 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-02-10 20:36:28 +0000 |
| commit | 42599b322db75b1cfdf4ab518532ddffd15066ac (patch) | |
| tree | 5835e341265b3493ba2d72ab57655922bfac3b8d /src/backend/tcop/pquery.c | |
| parent | 5cc8884a5d9f1d238a2098ebe6024f5d748c1f25 (diff) | |
| download | postgresql-42599b322db75b1cfdf4ab518532ddffd15066ac.tar.gz | |
Fix SPI cursor support to allow scanning the results of utility commands
that return tuples (such as EXPLAIN). Per gripe from Michael Fuhr.
Side effect: fix an old bug that unintentionally disabled backward scans
for all SPI-created cursors.
Diffstat (limited to 'src/backend/tcop/pquery.c')
| -rw-r--r-- | src/backend/tcop/pquery.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c index 496cbb43f8..d4d5b94594 100644 --- a/src/backend/tcop/pquery.c +++ b/src/backend/tcop/pquery.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.90 2005/02/01 23:28:40 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.91 2005/02/10 20:36:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1120,6 +1120,30 @@ PortalRunFetch(Portal portal, result = DoPortalRunFetch(portal, fdirection, count, dest); break; + case PORTAL_UTIL_SELECT: + + /* + * If we have not yet run the utility statement, do so, + * storing its results in the portal's tuplestore. + */ + if (!portal->portalUtilReady) + { + DestReceiver *treceiver; + + PortalCreateHoldStore(portal); + treceiver = CreateDestReceiver(Tuplestore, portal); + PortalRunUtility(portal, linitial(portal->parseTrees), + treceiver, NULL); + (*treceiver->rDestroy) (treceiver); + portal->portalUtilReady = true; + } + + /* + * Now fetch desired portion of results. + */ + result = DoPortalRunFetch(portal, fdirection, count, dest); + break; + default: elog(ERROR, "unsupported portal strategy"); result = 0; /* keep compiler quiet */ @@ -1170,7 +1194,8 @@ DoPortalRunFetch(Portal portal, { bool forward; - Assert(portal->strategy == PORTAL_ONE_SELECT); + Assert(portal->strategy == PORTAL_ONE_SELECT || + portal->strategy == PORTAL_UTIL_SELECT); switch (fdirection) { |
