Re: psql client quits after 1st command

Поиск
Список
Период
Сортировка
От Vincenzo Romano
Тема Re: psql client quits after 1st command
Дата
Msg-id 200703021726.05789.Vincenzo.Romano@gmail.com
обсуждение исходный текст
Ответ на Re: psql client quits after 1st command  (Douglas McNaught <doug@mcnaught.org>)
Ответы Re: psql client quits after 1st command  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
On Friday 02 March 2007 17:07 Douglas McNaught wrote:
> Vincenzo Romano <vincenzo.romano@gmail.com> writes:
> > Hi all.
> >
> > Under Linux I'm trying to communicate to an instance of the psql client
> > running in the background through a couple of named pipes.
> > I'd like to do something like this:
> >
> > $ mkfifo /tmp/pg_ipipe /tmp/pg_opipe
> > $ psql -d testdb -U testuser < /tmp/pg_ipipe > /tmp/pg_opipe &
> > ...
> > $ echo "\t" > /tmp/pg_ipipe
> > $ echo "select count(*) from test_table;" > /tmp/pg_ipipe
> > $ read COUNT < /tmp/pg_opipe
> >
> > The psql client connects to the DB abd waits for the first commad coming
> > from the "pg_ipipe" and executes it. Fine.
> > The problem is that it quits soon after instead of waiting for the second
> > (and any subsequent) command, as we all see in the usual command line
> > usage. I've also tried to add a "--file -" with no luck.
> > It seems that when the psql is getting the input from a named pipe acts
> > as if the "--command" option were active.
> >
> > I'm sure I'm missing something. But don't know what.
> > Is there any hint?
>
> psql gets an EOF on the named pipe when the first shell command
> exits.  You need to batch all your commands and send them in one shell
> command, so it keeps the pipe open until it's done.
>
> -Doug

Using "echo -n" instead of the plain "echo" to avoid sending the EOL makes the
psql client behaving the same way: quitting after the first complete command.
This makes useless the input redirection from anything other than a file.

I'm now going to read the sourcecode for the psql client.
Maybe it's a (kind of) bug in the psql code.

--
Vincenzo Romano
----
Maybe Computers will never become as intelligent as Humans.
For sure they won't ever become so stupid. [VR-1987]

В списке pgsql-general по дате отправления:

Предыдущее
От: Scott Ribe
Дата:
Сообщение: Re: PostgreSQL primary (sequence) key issue (Ruby/Rails)
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Add items to a record variable