diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 942264fbf9..827f4df3b2 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -540,7 +540,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res) showprompt = true; 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.")); } else showprompt = false; @@ -673,6 +673,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. *