Unformatted Copy into a Binary File
The quickest form of the COPY statement to code and execute for unloading data into a file is an unformatted copy. An unformatted copy always creates a file of type binary. This statement has the following format:
COPY [TABLE] [schema.]tablename () INTO 'output_filename'
[standard-with-clauses]
You omit the column list from the COPY statement. For example, the following statement copies the entire dept table into the dept_file file in binary format:
COPY dept () INTO 'dept_file';
The unformatted COPY INTO statement copies all rows of a table to the output file as binary data with minimal conversion, using the order and format of the columns in the table. It places no delimiters between fields or between records. It performs no type conversions; all data items retain the type they had in the table.
Unloading data with unformatted copy for backup can be inconvenient if you need to inspect the file data later.
Note: Columns that have a type other than character are not readable as characters in the output file.
If you unload a table with unformatted copy, the data must subsequently be reloaded with unformatted copy. You cannot use an unformatted output file to later load tables that have a different column order, number of columns, column data types. To perform these functions, use formatted COPY statements.
Last modified date: 08/14/2024