summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane2013-05-04 20:41:22 +0000
committerTom Lane2013-05-04 20:41:22 +0000
commit626e6eda4f605788110bfc5fa95760305f7eb749 (patch)
tree07bbf4c5ff3ee3296909fa4cbb0a747c58809945 /src
parent083d8fa79dbd693f48c1c195bf4f2af3d1e7dc67 (diff)
Improve behavior of \watch with non-tuple-returning commands.
Print the command tag if we get PGRES_COMMAND_OK, and throw an error for other cases. Per gripe from Michael Paquier. In passing, add an fflush(), just to be real sure the output appears before we sleep.
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/command.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 4e4c5bec7b2..0e997940328 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -2648,18 +2648,33 @@ do_watch(PQExpBuffer query_buf, long sleep)
printQuery(res, &myopt, pset.queryFout, pset.logfile);
break;
+ case PGRES_COMMAND_OK:
+ fprintf(pset.queryFout, "%s\n%s\n\n", title, PQcmdStatus(res));
+ break;
+
case PGRES_EMPTY_QUERY:
psql_error(_("\\watch cannot be used with an empty query\n"));
PQclear(res);
return false;
+ case PGRES_COPY_OUT:
+ case PGRES_COPY_IN:
+ case PGRES_COPY_BOTH:
+ psql_error(_("\\watch cannot be used with COPY\n"));
+ PQclear(res);
+ return false;
+
default:
- /* should we fail for non-tuple-result commands? */
- break;
+ /* other cases should have been handled by PSQLexec */
+ psql_error(_("unexpected result status for \\watch\n"));
+ PQclear(res);
+ return false;
}
PQclear(res);
+ fflush(pset.queryFout);
+
/*
* Set up cancellation of 'watch' via SIGINT. We redo this each time
* through the loop since it's conceivable something inside PSQLexec