Skip site navigation (1) Skip section navigation (2)

Re: Current-stream read for psql's \copy

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Mark Feit <mfeit+postgresql(at)notonthe(dot)net>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Current-stream read for psql's \copy
Date: 2004-02-10 14:26:28
Message-ID: 200402101426.i1AEQSY12826@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
Mark Feit wrote:
> This patch against 7.4.1's psql and the documentation adds the option
> of reading rows from the "current" input stream (standard input, -f
> xxx, \i xxx) during a "\copy ... from" operation in psql.  The details
> were proposed and discussed (somewhat) here:
> 
>   http://archives.postgresql.org/pgsql-hackers/2003-12/msg00687.php
>   http://archives.postgresql.org/pgsql-hackers/2004-01/msg00056.php
> 
> After some consideration, I decided to stick with the
> originally-proposed syntax because I couldn't come up with anything
> that made as much sense.
> 
> This patch also includes a change which makes the "enter data to be
> copied..." message appear for both \copy and COPY in an interactive
> setting.
> 
> If there's interest, I can build a patch against the current
> development version.

Actually, I am confused by our current \copy behavior.  Given the
following file:

	CREATE TABLE test(x INT);
	\copy test FROM STDIN
	444
	\.
	SELECT * FROM test;

'psql test </tmp/x' works fine, but 'psql -f /tmp/x test' hangs waiting
for input from stdin.  Why would we want STDIN to read from the terminal
if all commands are being read from a file with -f?

Reading the second URL, I see:

> Peter Eisentraut declared that from that point on, stdin would be
> whatever stream the \copy command came from.  I'd like to propose a
> variant on the "FROM" clause which makes good on Peter's declaration
> without breaking anything already using FROM STDIN and expecting it
> to really read from stdin.  (I think this is for the better because
> there are lots of good uses for "psql -f foo.sql < foo.dat".)

I agree with Peter stdin should be where ever the commands are coming
from.  I don't see any value to keeping backward compatibility for such
strange behavior, and adding another flag to give the reasonable
behavior seems wrong too.

I propose we just fix this and document it in the release notes.  Heck,
COPY and \copy should behave the same in determining STDIN, and right
now they don't.

-- 
  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

pgsql-hackers by date

Next:From: Bruce MomjianDate: 2004-02-10 14:29:19
Subject: Re: [PATCHES] Current-stream read for psql's \copy
Previous:From: Merlin MoncureDate: 2004-02-10 13:18:30
Subject: Re: MS SQL features for new version

pgsql-patches by date

Next:From: Bruce MomjianDate: 2004-02-10 14:29:19
Subject: Re: [PATCHES] Current-stream read for psql's \copy
Previous:From: Michael GlaesemannDate: 2004-02-10 14:01:18
Subject: Repost: Linking references in documentation

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group