Return-Path: pg_adm@postgres.berkeley.edu
Received: by postgres.Berkeley.EDU (5.61/1.29)
	id AA29771; Wed, 17 Jun 92 08:18:53 -0700
Message-Id: <9206171518.AA29771@postgres.Berkeley.EDU>
From: Stuart Pook <stuart@exogene.genethon.fr>
Subject: monitor -c "copy yacs from stdin"
To: postgres@postgres.berkeley.edu
Sender: pg_adm@postgres.berkeley.edu
Organization: Genethon, 13 Place de Rungis, 75013 Paris, France
 tel +33 1 45.65.13.00, fax +33 1 45.88.52.20
X-Face: "6o}6kk")qjUnYYq-`3_.vGq;@xj`3>#I/>4>E>DldCv:X#2%Rm+dr9HVN`g'#QgZFgsYsY
 .Q)bH:AoaW(n~=2B4aY?Q?{)1]&J+:LRX,qB>k{=6`K#2tRitzHKmi_9`}Lx0xdI*r!?MVNj7za"pZ
 *_QEm})y`y=vyyy~^0GY"HTvSCnv}eP*?{%zJ<r'BRk[r|J#;Im"Vp]!L
Date: Wed, 17 Jun 92 17:13:33 +0200
From: Stuart Pook <stuart@exogene.genethon.fr>

I sent this message to mao@postgres a while ago but got no reply,
so here it is again:

The follow command seems to cause some problems:
	some-command | monitor -c "copy yacs from stdin" yack

Firstly in the monitor there is a `fprintf(stdout, ">> ");' not
protected by a `if (!Silent)'.  This means that I get get _lots_ of
">> "'s written to stdout.

Secondly it says in the documentation for copy(commands) that:

   Similarly, if copy is reading from standard input, it will expect a
   period (.) followed by a newline, ..., to denote end-of-file.
   However, copy will terminate (followed by the backend itself) if a
   true EOF is encountered.

This does not appear to be the case.  There is no checking of EOF in
the monitor so if my `some-command' above does not end with an "." on a
line by itself the monitor will loop sending the last line of input to
the monitor.  The code looks like this:
                while (s[0] != '.')
                {
                    fprintf(stdout, ">> ");
                    gets(s);
                    PQputline(s);
                    PQputline("\n");
                }
The gets(s) fails and so the monitor sits in a loop sending the last
line read to the monitor.

Also this code exits whenever it sees a "." as the first character on
the line not a "." as the _only_ character on the line.  Thus the
monitor drops out of the read-from-stdin/write-to-backend loop but the
backend is still waiting for a "." on a line by itself.

Stuart Pook

PS.  And s is "char[100]"; what if my lines are longer than 100
     characters?  (And they are.)
PPS. How do you handle copies into a table with only one field where
     "." is a valid input line?  (Prepend a backslash?)
