Skip to content

\copy Parameters

FROM

You can copy data from either local source files or STDIN and load it into tables or columns in tables.

TO

You can copy data to either local output files or STDOUT, using a query, a table, or table columns as the source. The default output format is text.

FORMAT

The format of the input or output can be text, csv, or binary.

DELIMITER

A single one-byte character that represents the field delimiter, such as a pipe (|) or a comma (,).

NULL

The string that represents NULL values, such as '' (empty string).

HEADER

Whether the source (or destination file) contains a header row: 'true' or 'false'. If you are copying from a file and this option is set to 'true', the first line in the file will be skipped. This option applies to csv format only. If you specify the option header by itself, this also means 'true'.

QUOTE

A single one-byte character that is used when a data value is quoted. The default value is ". This option applies only to csv format.

ESCAPE

A single one-byte character that should appear before a data character that matches the QUOTE value. The default is the same as the QUOTE value (so that the quote character is doubled if it appears in the data). This option applies only to csv format.

FORCE_QUOTE

Adds quotes to output column values that are not NULL. NULL values are never quoted. You can quote specific columns in the table or all columns (*). This option applies only to \copy to commands that use csv format.

FORCE_NULL (column_list), FORCE_NOT_NULL (column_list)

Either match or do not match the values in the specified list of columns against the null string. Both options apply only to \copy from commands that use csv format.

FORCE_NOT_NULL: If a match is found, do not set the value to NULL. If the null string is empty (the default), empty values will be read and inserted as zero-length strings, not as NULL values, whether or not they are quoted.

FORCE_NULL: If a match is found, set the value to NULL. If the null string is empty, a quoted empty string is converted to NULL.

ENCODING

Typically set to 'utf8' or 'latin9'. For \copy from commands, see also the discussion of encodings in Creating Databases.

Parent topic:ybsql \copy Command