Re: how to redirect output to a file

Поиск
Список
Период
Сортировка
От Ron St-Pierre
Тема Re: how to redirect output to a file
Дата
Msg-id 4759644A.2070107@shaw.ca
обсуждение исходный текст
Ответ на Re: how to redirect output to a file  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Список pgsql-general
A. Kretschmer wrote:
> am  Tue, dem 04.12.2007, um 20:19:29 -0800 mailte pc folgendes:
>
>> Hi,
>>
>> How to redirect the output of an sql command to a file?
>> Thanks in advance
>>
>
> within psql you can use \o <filename>, from the shell you can use this:
>
> kretschmer@pegasus:~$ echo "select now()" | psql test > now.txt
> kretschmer@pegasus:~$ cat now.txt
>               now
> -------------------------------
>  2007-12-06 14:21:58.963405+01
> (1 row)
>
>
>
> Regards, Andreas
>
This is similar to Andreas' solution, and which we use in our shell scripts:

postgres@arya  ~]$ psql mydb -c "SELECT cola, colb, description FROM
myfile;" > myOutFile.txt

If the sql string contains multiple commands, they will be executed
within a single transaction, unless you use BEGIN/COMMIT within it to
split it up into multiple transactions.

Ron




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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: cannot dump structures
Следующее
От: "Josh Harrison"
Дата:
Сообщение: Re: Replication using WAL files