88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.31 2000/06/0401:44:33 petere Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.32 2000/06/0422:08:53 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
1515
1616#include "postgres.h"
1717
18+ #include "commands/command.h"
1819#include "executor/execdefs.h"
1920#include "executor/executor.h"
2021#include "tcop/pquery.h"
2122#include "utils/ps_status.h"
2223
23- #include "commands/command.h"
24-
2524static char * CreateOperationTag (int operationType );
2625static void ProcessQueryDesc (QueryDesc * queryDesc ,Node * limoffset ,
2726Node * limcount );
@@ -140,15 +139,32 @@ ProcessPortal(char *portalName,
140139MemoryContext portalContext ;
141140
142141/* ----------------
143- * convert the current blank portal into the user-specified
144- * portal and initialize the state and query descriptor.
142+ * Check for reserved or already-in-use portal name.
145143 * ----------------
146144 */
147145
148146if (PortalNameIsSpecial (portalName ))
149147elog (ERROR ,
150- "The portal name %s is reserved for internal use" ,
148+ "The portal name \"%s\" is reserved for internal use" ,
149+ portalName );
150+
151+ portal = GetPortalByName (portalName );
152+ if (PortalIsValid (portal ))
153+ {
154+ /* XXX Should we raise an error rather than closing the old portal? */
155+ elog (NOTICE ,"Closing pre-existing portal \"%s\"" ,
151156portalName );
157+ PortalDrop (& portal );
158+ }
159+
160+ /* ----------------
161+ * Convert the current blank portal into the user-specified
162+ * portal and initialize the state and query descriptor.
163+ *
164+ * Since the parsetree has been created in the current blank portal,
165+ * we don't have to do any work to copy it into the user-named portal.
166+ * ----------------
167+ */
152168
153169portal = BlankPortalAssignName (portalName );
154170
@@ -159,8 +175,8 @@ ProcessPortal(char *portalName,
159175PortalCleanup );
160176
161177/* ----------------
162- *now create a new blank portal and switch to it.
163- *Otherwise, the new named portal will be cleaned.
178+ *Now create a new blank portal and switch to it.
179+ *Otherwise, the new named portal will be cleaned at statement end .
164180 *
165181 *Note: portals will only be supported within a BEGIN...END
166182 *block in the near future. Later, someone will fix it to