psql database_tst
//将查询语句写入文件
database_tst=#>\w /tmp/write.txt
database_tst=#>select * from views;
//将查询结果写入文件
database_tst=#>\o /tmp/write.txt
database_tst=#>select * from views;
//列状显示
database_tst=#>\x
database_tst=#>select * from views;
/?
//查询更多用法
将SQL查询结果导出为数据文件:
1. 首先创建一个临时表
database_tst=#> create table tmp_views as select * from views where id > 10 and id < 1;
2. 其次将该临时表倒出来
[code]
pg_dump -a -t tmp_views -F c -f dataware_views.pgsql -Z 9 database_tst
[/code]
3.删除掉没用的临时表吧
[code]
database_tst=#> begin;
database_tst=#> drop table tmp_views;
database_tst=#>commit;
[/code]