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:

[EMAIL PROTECTED]:~$ echo "select now()" | psql test > now.txt
[EMAIL PROTECTED]:~$ 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:

[EMAIL PROTECTED] ~]$ 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




---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

              http://www.postgresql.org/docs/faq

Reply via email to