Subject: monitor -c "copy yacs from stdin"

From: Stuart Pook <[email-masked]>
Date: Wed, 17 Jun 92 17:13:33 +0200

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

---

From: postarch (Postgres Mailing Archive)
Date: Mon, 27 Jul 92 11:46:55 PDT

> line read to the monitor.

These problems will be fixed in 4.0.1, coming soon to an ftp site near you.

>      characters?  (And they are.)

I have increased the size of the array to 8192, but in general you could
write your own simple front-end application (e.g. if 8192 isn't big enough)
to do copying.

>      "." is a valid input line?  (Prepend a backslash?)

Prepend a backslash.

Jeff Meredith
[email-masked]