*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.245.2.1 2002/02/26 23:48:45 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.245.2.2 2002/02/27 23:17:01 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
/* Transaction control statements need some special handling */
isTransactionStmt = IsA(parsetree, TransactionStmt);
+ /*
+ * First we set the command-completion tag to the main query
+ * (as opposed to each of the others that may be generated by
+ * analyze and rewrite). Also set ps_status to the main query tag.
+ */
+ commandTag = CreateCommandTag(parsetree);
+
+ set_ps_display(commandTag);
+
/*
* If we are in an aborted transaction, ignore all commands except
* COMMIT/ABORT. It is important that this test occur before we
/*
* OK to analyze and rewrite this query.
- */
-
- /*
- * First we set the command-completion tag to the main query
- * (as opposed to each of the others that may be generated by
- * analyze and rewrite). Also set ps_status to the main query tag.
- */
- commandTag = CreateCommandTag(parsetree);
-
- set_ps_display(commandTag);
-
- /*
+ *
* Switch to appropriate context for constructing querytrees (again,
* these must outlive the execution context).
*/
} /* end loop over queries generated from a
* parsetree */
+ /*
+ * If this is the last parsetree of the query string, close down
+ * transaction statement before reporting command-complete. This is
+ * so that any end-of-transaction errors are reported before the
+ * command-complete message is issued, to avoid confusing clients
+ * who will expect either a command-complete message or an error,
+ * not one and then the other. But for compatibility with
+ * historical Postgres behavior, we do not force a transaction
+ * boundary between queries appearing in a single query string.
+ */
+ if (lnext(parsetree_item) == NIL && xact_started)
+ {
+ finish_xact_command();
+ xact_started = false;
+ }
+
/*
* It is possible that the original query was removed due to
* a DO INSTEAD rewrite rule. In that case we will still have
* Tell client that we're done with this query. Note we emit
* exactly one EndCommand report for each raw parsetree, thus
* one for each SQL command the client sent, regardless of
- * rewriting.
+ * rewriting. (But a command aborted by error will not send
+ * an EndCommand report at all.)
*/
EndCommand(commandTag, dest);
} /* end loop over parsetrees */
/*
* Close down transaction statement, if one is open.
+ * (Note that this will only happen if the querystring was empty.)
*/
if (xact_started)
finish_xact_command();
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.245.2.1 $ $Date: 2002/02/26 23:48:45 $\n");
+ puts("$Revision: 1.245.2.2 $ $Date: 2002/02/27 23:17:01 $\n");
}
/*