stdin/stdout mismatch for COPY and \copy

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Mark Feit <mfeit+postgresql(at)notonthe(dot)net>
Subject: stdin/stdout mismatch for COPY and \copy
Date: 2004-04-09 17:35:58
Message-ID: 200404091735.i39HZwg25925@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > Tom Lane wrote:
> >> No it doesn't. EOF will do fine. The source program doesn't
> >> necessarily have to know anything about COPY, as long as its output is
> >> in a format COPY can cope with (eg, tab-delimited).
>
> > The current behavior seems quite strange and counter-intuitive. We
> > might break the code for 1-2 people, but we will make it more
> > predicable for everyone using it.
>
> I don't think it's acceptable to simply remove the functionality.
> If you wanted to argue about swapping the meanings of STDIN and -
> (as defined by the patch) then we could debate about which way is
> more consistent and whether it's worth breaking backwards compatibility
> to improve consistency. I could probably be talked into supporting
> that; as you say, we've done that before. But taking out a useful
> behavior that has been there a long time, simply because you've decided
> it's unintuitive, is not okay.

I am reviewing our addition of '-' in CVS for psql \copy.

Reading the manual, I think our current code is pretty confusing/contorted:

For \copy table from filename operations, psql adds the option of using
a hyphen instead of filename. This causes \copy to read rows from the
same source that issued the command, continuing until \. is read or the
stream reaches EOF. This option is useful for populating tables in-line
within a SQL script file. In contrast, \copy from stdin always reads
from psql's standard input.

...

Note: Note the difference in interpretation of stdin and stdout between
\copy and COPY. In \copy these always refer to psql's input and output
streams. In COPY, stdin comes from wherever the COPY itself came from
(for example, a script run with the -f option), while stdout refers to
the query output stream (see \o meta-command below).

"stdin is stdin except when it isn't stdin." :-)

I think the biggest problem is that stdin/stdout in COPY is different
from \copy. I propose we make stdin/stdout consistent for COPY and
\copy, where stdin always reads from command input, and stdout always
writes to command output. This does break backward compatibility of
\copy for stdin/stdout; this change would have to be mentioned in the
release notes. COPY is unaffected.

I propose we add 'pstdin', and 'pstdout' to read from psql's stdin and
stdout. I think that will greatly simplify our documentation, and
clarify the stdin/stdout usage in all cases.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2004-04-09 17:36:45 Re: Code Sprint at OSCON?
Previous Message Josh Berkus 2004-04-09 17:32:11 Code Sprint at OSCON?

Browse pgsql-patches by date

  From Date Subject
Next Message Magnus Hagander 2004-04-09 17:38:59 Re: New socket code for win32
Previous Message Tom Lane 2004-04-09 06:07:14 Re: Checking for USAGE on SET search_path...