Re: how to redirect output to a file - Mailing list pgsql-general

From Ron St-Pierre
Subject Re: how to redirect output to a file
Date
Msg-id 4759644A.2070107@shaw.ca
Whole thread Raw
In response to Re: how to redirect output to a file  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List 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 by date:

Previous
From: Tom Lane
Date:
Subject: Re: cannot dump structures
Next
From: "Josh Harrison"
Date:
Subject: Re: Replication using WAL files