Return-Path: postarch
Received: by postgres.Berkeley.EDU (5.61/1.29)
	id AA16625; Mon, 27 Jul 92 11:47:16 -0700
Message-Id: <9207271847.AA16625@postgres.Berkeley.EDU>
From: postarch (Postgres Mailing Archive)
Subject: Re: monitor -c "copy yacs from stdin"
To: postgres@postgres.berkeley.edu
Sender: pg_adm@postgres.berkeley.edu
Reply-To: mer@postgres.berkeley.edu
In-Reply-To: Your message of "Wed, 17 Jun 92 17:13:33 +0200."
             <9206171518.AA29771@postgres.Berkeley.EDU> 
Date: Mon, 27 Jul 92 11:46:55 PDT

you write:

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

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

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

> PS.  And s is "char[100]"; what if my lines are longer than 100
>      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.

> PPS. How do you handle copies into a table with only one field where
>      "." is a valid input line?  (Prepend a backslash?)

Prepend a backslash.


Jeff Meredith
mer@postgres.berkeley.edu
