Copy Data into a Formatted File
Use the following COPY statement to copy table data into a formatted file:
COPY [TABLE] [schema.]tablename
([column_name = format [WITH NULL [(value)]]
{, column_name = format [WITH NULL[(value)]]}])
INTO 'output_filename' [standard-with-clauses]
One or more column names appear, with format specifications. The column names must be the same as those in the table. However, the order of the columns can be different from the order in which they are currently stored in the table (except as noted below). Also, the format does not have to be the same data type or length as their corresponding entries in the table. The data is copied with any column reorganization or format conversions being made as necessary.
Note: When copying from a table that includes long varchar or long byte columns, you must specify the columns in the order they appear in the table.
Two major categories of data that can be unloaded into files are fixed-length fields and variable-length fields.