如何将查询结果从 Postgres 导出到 CSV 文件

How to export query results from Postgres to a CSV file

我是 Postgres 的初学者,正在尝试弄清楚如何将我的数据输出(结果)导出到 Excel 或 CSV 文件。我能够将我的结果导出到 CSV 文件中,但结果与我在 "Data Output" 窗格中收到的结果不完全一样。有没有办法让我在我的 Postgres 输出窗格中完全看到 - CSV 或 Excel 文件中的数据输出?

请帮忙..

复制命令是执行此操作的最佳方式:

http://www.postgresql.org/docs/9.3/static/sql-copy.html

COPY table_name [ ( column_name [, ...] ) ] FROM { 'filename' | PROGRAM 'command' | STDIN } [ [ WITH ] ( option [, ...] ) ]

COPY { table_name [ ( column_name [, ...] ) ] | ( query ) } TO { 'filename' | PROGRAM 'command' | STDOUT } [ [ WITH ] ( option [, ...] ) ]

where option can be one of:

FORMAT format_name
OIDS [ boolean ]
FREEZE [ boolean ]
DELIMITER 'delimiter_character'
NULL 'null_string'
HEADER [ boolean ]
QUOTE 'quote_character'
ESCAPE 'escape_character'
FORCE_QUOTE { ( column_name [, ...] ) | * }
FORCE_NOT_NULL ( column_name [, ...] )
ENCODING 'encoding_name'