Make psql handle EOF during COPY FROM STDIN properly on all platforms.
Make psql handle EOF during COPY FROM STDIN properly on all platforms.

When stdin is a terminal, it's possible to end a COPY FROM STDIN with
a keyboard EOF signal (typically control-D), and then keep on issuing
SQL commands.  One would expect another COPY FROM STDIN to work as well,
but on some platforms it did not.  This turns out to be because we were
not resetting the stream's feof() flag, and BSD-ish versions of fread()
and fgets() won't attempt to read more data if that's set.

The misbehavior is observed on BSDen (including macOS), but not Linux,
Windows, or SysV-ish Unixen, which makes this a portability bug not
just a missing feature.

Add a clearerr() call to fix the behavior, and improve the prompt that's
issued when copying from a TTY to mention that EOF signals work.

It's been like this forever, so back-patch to all supported branches.

Thomas Munro

Discussion: 7d7bac0100e9bb94e7a4acf66a27006267791ccc@mail.gmail.com

xinzweb/gpdb,xinzweb/gpdb,adam8157/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,lisakowen/gpdb,lisakowen/gpdb,jmcatamney/gpdb,lisakowen/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,adam8157/gpdb,adam8157/gpdb,xinzweb/gpdb,jmcatamney/gpdb,50wu/gpdb,50wu/gpdb,xinzweb/gpdb,xinzweb/gpdb,lisakowen/gpdb,jmcatamney/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,lisakowen/gpdb,lisakowen/gpdb,50wu/gpdb,adam8157/gpdb,lisakowen/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,greenplum-db/gpdb,adam8157/gpdb,50wu/gpdb,adam8157/gpdb,50wu/gpdb,ashwinstar/gpdb,50wu/gpdb,ashwinstar/gpdb,adam8157/gpdb,ashwinstar/gpdb,xinzweb/gpdb,50wu/gpdb,lisakowen/gpdb,jmcatamney/gpdb,50wu/gpdb,xinzweb/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,adam8157/gpdb,xinzweb/gpdb,jmcatamney/gpdb,ashwinstar/gpdb