Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 626e6ed

Browse files
committed
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.
1 parent 083d8fa commit 626e6ed

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/bin/psql/command.c

+17-2
Original file line numberDiff line numberDiff line change
@@ -2648,18 +2648,33 @@ do_watch(PQExpBuffer query_buf, long sleep)
26482648
printQuery(res, &myopt, pset.queryFout, pset.logfile);
26492649
break;
26502650

2651+
case PGRES_COMMAND_OK:
2652+
fprintf(pset.queryFout, "%s\n%s\n\n", title, PQcmdStatus(res));
2653+
break;
2654+
26512655
case PGRES_EMPTY_QUERY:
26522656
psql_error(_("\\watch cannot be used with an empty query\n"));
26532657
PQclear(res);
26542658
return false;
26552659

2660+
case PGRES_COPY_OUT:
2661+
case PGRES_COPY_IN:
2662+
case PGRES_COPY_BOTH:
2663+
psql_error(_("\\watch cannot be used with COPY\n"));
2664+
PQclear(res);
2665+
return false;
2666+
26562667
default:
2657-
/* should we fail for non-tuple-result commands? */
2658-
break;
2668+
/* other cases should have been handled by PSQLexec */
2669+
psql_error(_("unexpected result status for \\watch\n"));
2670+
PQclear(res);
2671+
return false;
26592672
}
26602673

26612674
PQclear(res);
26622675

2676+
fflush(pset.queryFout);
2677+
26632678
/*
26642679
* Set up cancellation of 'watch' via SIGINT. We redo this each time
26652680
* through the loop since it's conceivable something inside PSQLexec

0 commit comments

Comments
 (0)