From 9af72adb1540d13c382973e2c3c012476254d96b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 24 Nov 2006 23:06:56 +0000 Subject: [PATCH] Fix psql's \copy command to ensure that it cycles libpq back to the idle state (in particular, causing the ReadyForQuery message to be eaten) before returning from do_copy. The only known consequence of failing to do so is that get_prompt might show a wrong result for the %x transaction status escape, as reported by Bernd Helmle; but it's possible there are other issues. Back-patch as far as 7.4, the oldest version supporting %x. --- src/bin/psql/copy.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index a69c63957b..800fff204a 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -573,6 +573,18 @@ do_copy(const char *args) PQclear(result); + /* + * Make sure we have pumped libpq dry of results; else it may still be + * in ASYNC_BUSY state, leading to false readings in, eg, get_prompt(). + */ + while ((result = PQgetResult(pset.db)) != NULL) + { + success = false; + psql_error("\\copy: unexpected response (%d)\n", + PQresultStatus(result)); + PQclear(result); + } + if (options->file != NULL) { if (fclose(copystream) != 0) -- 2.39.5