diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 2005b9a0bfc..d9435c297b0 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; @@ -674,6 +674,15 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res) copyin_cleanup: /* + * Clear the EOF flag on the stream, in case copying finished with an EOF + * signal. An interactive TTY session may need to reuse the stream for a + * later COPY command. Although we don't ever test the flag with feof(), + * some fread() implementations won't wait for more data until we clear + * it. + */ + 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