summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/psql/copy.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index 4b749154adf..740f07bb196 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -542,7 +542,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
{
if (!pset.quiet)
puts(_("Enter data to be copied followed by a newline.\n"
- "End with a backslash and a period on a line by itself."));
+ "End with a backslash and a period on a line by itself, or an EOF signal."));
prompt = get_prompt(PROMPT_COPY);
}
else
@@ -670,6 +670,16 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
copyin_cleanup:
/*
+ * Clear the EOF flag on the stream, in case copying ended due to an EOF
+ * signal. This allows an interactive TTY session to perform another COPY
+ * FROM STDIN later. (In non-STDIN cases, we're about to close the file
+ * anyway, so it doesn't matter.) Although we don't ever test the flag
+ * with feof(), some fread() implementations won't read more data if it's
+ * set. This also clears the error flag, but we already checked that.
+ */
+ clearerr(copystream);
+
+ /*
* Check command status and return to normal libpq state.
*
* We do not want to return with the status still PGRES_COPY_IN: our