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 @@ -669,6 +669,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. *