COPY at PostgreSQL Exchange data between a table and a standard file system file. COPYTO Copy all the contents of a table to a file, and COPYFROM copy data from a file into a table (append the data to the existing content in the tables).
COPY table name to ' file name . csv ' csv HEADER;
Note:CSV
open Comma separated variables (CSV ) mode.
HEADER
The declaration file contains a header identification row that contains the name of each field in the file. When output, the first row contains the field name of the table, and the first row is ignored when entered.
A COPY with the file name instructs the PostgreSQL server to read and write data directly from the file. If a file name is declared, it must be visible to the server, and the filename must be declared from the server's perspective. If STDIN or STDOUTis declared, the data flows through the connection between the customer's front end and the server.
Http://www.php100.com/manual/PostgreSQL8/sql-copy.html
PostgreSQL data table converted to Excel