02-psql-copy-watch-fix.patch

text/plain

Filename: 02-psql-copy-watch-fix.patch
Type: text/plain
Part: 1
Message: [patch] \g with multiple result sets and \watch with copy queries

Patch

Format: unified
File+
src/bin/psql/common.c 5 9
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 88f4b159f9..5864a9833f 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1351,10 +1351,9 @@ DescribeQuery(const char *query, double *elapsed_msec)
  *
  * Sends query and cycles through PGresult objects.
  *
- * When not under \watch and if our command string contained a COPY FROM STDIN
- * or COPY TO STDOUT, the PGresult associated with these commands must be
- * processed by providing an input or output stream.  In that event, we'll
- * marshal data for the COPY.
+ * If our command string contained a COPY FROM STDIN or COPY TO STDOUT, the
+ * PGresult associated with these commands must be processed by providing an
+ * input or output stream.  In that event, we'll marshal data for the COPY.
  *
  * For other commands, the results are processed normally, depending on their
  * status.
@@ -1491,12 +1490,9 @@ ExecQueryAndProcessResults(const char *query, double *elapsed_msec, bool *svpt_g
 
 			if (is_watch)
 			{
-				ClearOrSaveAllResults();
-				pg_log_error("\\watch cannot be used with COPY");
-				return -1;
+				copy_stream = printQueryFout ? printQueryFout : pset.queryFout;
 			}
-
-			if (pset.copyStream) /* invoked by \copy */
+			else if (pset.copyStream) /* invoked by \copy */
 			{
 				copy_stream = pset.copyStream;
 			}