diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 71f0c8a..925bb72 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -29,6 +29,7 @@
 static bool ExecQueryUsingCursor(const char *query, double *elapsed_msec);
 static bool command_no_begin(const char *query);
 static bool is_select_command(const char *query);
+static bool PrintQueryResults(PGresult *results);
 
 /*
  * setQFout
@@ -644,6 +645,7 @@ ProcessResult(PGresult **results)
 	PGresult   *next_result;
 	bool		success = true;
 	bool		first_cycle = true;
+	PGresult	*intres;
 
 	do
 	{
@@ -691,10 +693,16 @@ ProcessResult(PGresult **results)
 			 */
 			SetCancelConn();
 			if (result_status == PGRES_COPY_OUT)
-				success = handleCopyOut(pset.db, pset.queryFout) && success;
+				success = handleCopyOut(pset.db, pset.queryFout, &intres) && success;
 			else
 				success = handleCopyIn(pset.db, pset.cur_cmd_source,
-									   PQbinaryTuples(*results)) && success;
+									   PQbinaryTuples(*results), &intres) && success;
+
+			if (success && intres)
+				success = PrintQueryResults(intres);
+			
+			PQclear(intres);
+
 			ResetCancelConn();
 
 			/*
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index 6db063c..347b866 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -433,12 +433,11 @@ do_copy(const char *args)
  * result is true if successful, false if not.
  */
 bool
-handleCopyOut(PGconn *conn, FILE *copystream)
+handleCopyOut(PGconn *conn, FILE *copystream, PGresult **res)
 {
 	bool		OK = true;
 	char	   *buf;
 	int			ret;
-	PGresult   *res;
 
 	for (;;)
 	{
@@ -490,19 +489,18 @@ handleCopyOut(PGconn *conn, FILE *copystream)
 	 * TO STDOUT commands.	We trust that no condition can make PQexec() fail
 	 * indefinitely while retaining status PGRES_COPY_OUT.
 	 */
-	while (res = PQgetResult(conn), PQresultStatus(res) == PGRES_COPY_OUT)
+	while (*res = PQgetResult(conn), PQresultStatus(*res) == PGRES_COPY_OUT)
 	{
 		OK = false;
-		PQclear(res);
+		PQclear(*res);
 
 		PQexec(conn, "-- clear PGRES_COPY_OUT state");
 	}
-	if (PQresultStatus(res) != PGRES_COMMAND_OK)
+	if (PQresultStatus(*res) != PGRES_COMMAND_OK)
 	{
 		psql_error("%s", PQerrorMessage(conn));
 		OK = false;
 	}
-	PQclear(res);
 
 	return OK;
 }
@@ -523,12 +521,11 @@ handleCopyOut(PGconn *conn, FILE *copystream)
 #define COPYBUFSIZ 8192
 
 bool
-handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary)
+handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
 {
 	bool		OK;
 	const char *prompt;
 	char		buf[COPYBUFSIZ];
-	PGresult   *res;
 
 	/*
 	 * Establish longjmp destination for exiting from wait-for-input. (This is
@@ -682,19 +679,18 @@ copyin_cleanup:
 	 * indefinitely while retaining status PGRES_COPY_IN, we get an infinite
 	 * loop.  This is more realistic than handleCopyOut()'s counterpart risk.
 	 */
-	while (res = PQgetResult(conn), PQresultStatus(res) == PGRES_COPY_IN)
+	while (*res = PQgetResult(conn), PQresultStatus(*res) == PGRES_COPY_IN)
 	{
 		OK = false;
-		PQclear(res);
+		PQclear(*res);
 
 		PQputCopyEnd(pset.db, _("trying to exit copy mode"));
 	}
-	if (PQresultStatus(res) != PGRES_COMMAND_OK)
+	if (PQresultStatus(*res) != PGRES_COMMAND_OK)
 	{
 		psql_error("%s", PQerrorMessage(conn));
 		OK = false;
 	}
-	PQclear(res);
 
 	return OK;
 }
diff --git a/src/bin/psql/copy.h b/src/bin/psql/copy.h
index dfc61ee..99e923a 100644
--- a/src/bin/psql/copy.h
+++ b/src/bin/psql/copy.h
@@ -16,7 +16,7 @@ bool		do_copy(const char *args);
 
 /* lower level processors for copy in/out streams */
 
-bool		handleCopyOut(PGconn *conn, FILE *copystream);
-bool		handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary);
+bool		handleCopyOut(PGconn *conn, FILE *copystream, PGresult **res);
+bool		handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res);
 
 #endif
