利用sql命令把结果集输出到文件

红色部分的三条命令完成把结果集输出到文件!!

[root@test root]# psql -hlocalhost -Utest test
Welcome to psql 8.0.3, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

gudumami=# \f ,
Field separator is ",".
gudumami=# \o /tmp/test.csv
gudumami=# SELECT * WHERE test ORDER BY id;
gudumami=# \q

 

摘自:http://www.cnblogs.com/coffee_cn/articles/1606926.html

posted on 2013-09-27 11:50  newmanzhang  阅读(429)  评论(0编辑  收藏  举报

导航