summaryrefslogtreecommitdiff
path: root/src/backend/utils/mmgr/portalmem.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-08-14 22:57:15 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-08-14 22:57:15 +0000
commit65b2f93b587be67ea1d5e4d98a99599937aa7b19 (patch)
treefdb266a0f1070e45df5385b6721d6b0a9998675f /src/backend/utils/mmgr/portalmem.c
parent3d1e01caa46b87b734e4758ad9885e1e12bc77c8 (diff)
downloadpostgresql-65b2f93b587be67ea1d5e4d98a99599937aa7b19.tar.gz
Fix oversight in initial implementation of PORTAL_ONE_RETURNING mode: we
cannot assume that there's exactly one Query in the Portal, as we can for ONE_SELECT mode, because non-SELECT queries might have extra queries added during rule rewrites. Fix things up so that we'll use ONE_RETURNING mode when a Portal contains one primary (canSetTag) query and that query has a RETURNING list. This appears to be a second showstopper reason for running the Portal to completion before we start to hand anything back --- we want to be sure that the rule-added queries get run too.
Diffstat (limited to 'src/backend/utils/mmgr/portalmem.c')
-rw-r--r--src/backend/utils/mmgr/portalmem.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c
index da4aee4d16..85a6711d1c 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -12,7 +12,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.91 2006/08/08 01:23:15 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.92 2006/08/14 22:57:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -147,6 +147,34 @@ GetPortalByName(const char *name)
}
/*
+ * PortalListGetPrimaryQuery
+ * Get the "primary" Query within a portal, ie, the one marked canSetTag.
+ *
+ * Returns NULL if no such Query. If multiple Query structs within the
+ * portal are marked canSetTag, returns the first one. Neither of these
+ * cases should occur in present usages of this function.
+ *
+ * Note: the reason this is just handed a List is so that prepared statements
+ * can share the code. For use with a portal, use PortalGetPrimaryQuery
+ * rather than calling this directly.
+ */
+Query *
+PortalListGetPrimaryQuery(List *parseTrees)
+{
+ ListCell *lc;
+
+ foreach(lc, parseTrees)
+ {
+ Query *query = (Query *) lfirst(lc);
+
+ Assert(IsA(query, Query));
+ if (query->canSetTag)
+ return query;
+ }
+ return NULL;
+}
+
+/*
* CreatePortal
* Returns a new portal given a name.
*