Re: COPY FROM STDIN behaviour on end-of-file

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: Vaishnavi Prabakaran <vaishnaviprabakaran(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FROM STDIN behaviour on end-of-file
Date: 2017-05-17 16:31:35
Message-ID: 27246.1495038695@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> writes:
> On Wed, May 17, 2017 at 2:39 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Thanks for checking. So that's two major platforms where it works "as
>> expected" already.

> Ah... the reason this is happening is that BSD-derived fread()
> implementations return immediately if the EOF flag is set[1], but
> others do not.

Hah, good detective work. I tried this on the lone SysV-derived box
I have (ancient HPUX), and did not see the problem, so that seems to
confirm the comment you found that says this is a SysV-tradition vs
BSD-tradition thing.

>> If we're going
>> to go out of our way to make it work, should we mention it in psql-ref?

> I went looking for the place to put that and found that it already says:

> For <literal>\copy ... from stdin</>, data rows are read from the same
> source that issued the command, continuing until <literal>\.</literal>
> is read or the stream reaches <acronym>EOF</>.

Yeah, it seems like that's clear enough already; I don't feel a need to
complicate it.

Another thing that would be nice is a regression test, but I don't see
any way to do that in our standard test environments. I could imagine
building a test rig that fires up psql through a PTY, but making it
portable is a daunting prospect, and probably not worth the trouble.

> Here's a version incorporating your other suggestions and a comment to explain.

I editorialized on the comment a bit and pushed it. Thanks for the
report and patch!

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2017-05-17 16:34:31 Re: [bug fix] PG10: libpq doesn't connect to alternative hosts when some errors occur
Previous Message Remi Colinet 2017-05-17 16:31:15 Re: [PATCH v2] Progress command to monitor progression of long running SQL queries