From: | Ron St-Pierre <ron(dot)pgsql(at)shaw(dot)ca> |
---|---|
To: | chavanpriya(at)gmail(dot)com |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: how to redirect output to a file |
Date: | 2007-12-07 15:18:34 |
Message-ID: | 4759644A.2070107@shaw.ca |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)pegasus:~$ echo "select now()" | psql test > now.txt
> kretschmer(at)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(at)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
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Harrison | 2007-12-07 15:51:02 | Re: Replication using WAL files |
Previous Message | Tom Lane | 2007-12-07 15:12:27 | Re: cannot dump structures |