Appearance
COPY
Copy data to a table from STDIN, or copy data from a table or query to STDOUT. Any user can copy data with this command. See also ybsql \copy Command, which you can use to copy data to and from files.
Syntax
COPY table_name [ ( column_name [, ...] ) ]
FROM STDIN [ [ WITH ] ( option [, ...] ) ]
COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
TO STDOUT [ [ WITH ] ( option [, ...] ) ]
where option is:
FORMAT text | csv | binary
DELIMITER 'delimiter_character'
NULL 'null_string'
HEADER [ 'true' | 'false' ]
QUOTE 'quote_character'
ESCAPE 'escape_character'
FORCE_QUOTE { ( column_name [, ...] ) | * }
FORCE_NULL ( column_name [, ...] )
FORCE_NOT_NULL ( column_name [, ...] )
ENCODING 'encoding_name'Note: The options list is enclosed in parentheses and separated by commas. The WITH keyword is not required.
For example:
premdb=# copy season to stdout;
1 1992-1993 22 Manchester United
2 1993-1994 22 Manchester United
3 1994-1995 22 Blackburn Rovers
4 1995-1996 20 Manchester United
5 1996-1997 20 Manchester United
6 1997-1998 20 Arsenal
...premdb=# copy season to stdout with (format csv);
1,1992-1993,22,Manchester United
2,1993-1994,22,Manchester United
3,1994-1995,22,Blackburn Rovers
4,1995-1996,20,Manchester United
5,1996-1997,20,Manchester United
6,1997-1998,20,Arsenal
...Parent topic:SQL Commands