diff options
-rw-r--r-- | src/bin/psql/copy.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 2005b9a0bfc..7ed339ab6dc 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,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 |