Re: 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: Re: stdin/stdout mismatch for COPY and \copy
Date: 2004-04-09 18:11:20
Message-ID: 200404091811.i39IBK105518@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:
> > 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.
>
> What is "command output" and how does that differ from stdout?
>
> I see the need to distinguish command input from psql stdin, since psql
> may be reading the command from a file, but I don't see where there's
> a stdout difference.
>
> "pstdin" seems a bit contrived; I'm just as happy with using "-" as
> the existing patch did. I'm fine with swapping the meanings to bring
> \copy into line with COPY, though.

pstdout can be illustrated by this:

$ sql -f /tmp/x test
DROP TABLE
CREATE TABLE
INSERT 17225 1
1
$ sql -f /tmp/x -o /tmp/y test
1

where /tmp/x is:

DROP TABLE test;
CREATE TABLE test (x int);
INSERT INTO test VALUES (1);
\copy test to stdout

In this case, stdout is going to psql's stdout, not to the command
stdout.

The reason I didn't like '-' is that it is used mostly in Unix as
synonym for stdin, and in this case it isn't a synonym --- it actually
has different behavior. Using '-' which is a synonym for stdin causes
confusion.

I thought pstdin/pstdout were very clear in helping folks remember how
it is different from stdin/stdout. Certainly it is contrived. Do you
like appstdin and appstdout better, or psqlstdin and psqlstdout?

--
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 Tom Lane 2004-04-09 18:20:55 Re: stdin/stdout mismatch for COPY and \copy
Previous Message Tom Lane 2004-04-09 17:59:33 Re: stdin/stdout mismatch for COPY and \copy

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2004-04-09 18:20:55 Re: stdin/stdout mismatch for COPY and \copy
Previous Message Andrew Dunstan 2004-04-09 18:08:21 Re: COPY for CSVs