
They must be accessible to and readable or writable by the PostgreSQL user (the user ID the server

Therefore, they must reside on or beĪccessible to the database server machine, not the client. It is sufficient to have column privileges on the column(s) listed in the command.įiles named in a COPY command are read or written directly by the server, not by the client application. You must have select privilege on the table whose values are read by COPY TO, and insert privilege on the table into which values are inserted byĬOPY FROM. Will not work to output binary data from a smallint column and read it into an integer column, even though that would work fine in text format. Also, the binary format is very data type specific for example it
#LINUX COPYQ PORTABLE#
It is somewhat faster than the normal text mode, but aīinary-format file is less portable across machine architectures and PostgreSQL versions. The BINARY key word causes all data to be stored/read as binary format rather than as text. However, you can write COPY (SELECT * FROM viewname) TO. On successful completion, a COPY command returns a command tag of the formĬOPY can only be used with plain tables, not with views. (''), this causes missing values to be input as zero-length strings. NULL output is never quoted.įORCE NOT NULL In CSV COPY FROM mode, process each specified column as though it were quoted and hence not a NULL value. The default is the QUOTE value (usuallyįORCE QUOTE In CSV COPY TO mode, forces quoting to be used for all non-NULL values in each specified column. Specifies the ASCII character that should appear before a QUOTE data character value in CSV mode. Specifies the ASCII quotation character in CSV mode. Table, and on input, the first line is ignored. On output, the first line contains the column names from the Specifies that the file contains a header line with the names of each column in the file. Selects Comma Separated Value (CSV) mode. Note: When using COPY FROM, any data item that matches this string will be stored as a null value, so you should make sure that you use the String even in text mode for cases where you don't want to distinguish nulls from empty strings. The default is \N (backslash-N) in text mode, and an unquoted empty string in CSV mode. Null string The string that represents a null value. The default is a tab character in text mode, a comma in CSV (An error is raised if OIDS is specified for a table that does not have OIDs, or in the case of copying aĭelimiter The single ASCII character that separates columns within each row (line) of the file. You cannot specify the DELIMITER, NULL, or CSV options in Specifies that output goes to the client application.Ĭauses all data to be stored or read in binary format rather than as text. Specifies that input comes from the client application.
#LINUX COPYQ WINDOWS#
Windows users might need to use an E'' string and double backslashes used as path separators.

Note that parentheses are required around theįilename The absolute path name of the input or output file. If no column list is specified, all columns of the table will be copied.Ī SELECT or VALUES command whose results are to be copied. Tablename The name (optionally schema-qualified) of an existing table.Īn optional list of columns to be copied. When STDIN or STDOUT is specified, data is transmitted via the connection between the client and the

Name must be specified from the viewpoint of the server. The file must be accessible to the server and the

That are not in the column list, COPY FROM will insert the default values for those columns.ĬOPY with a file name instructs the PostgreSQL server to directly read from or write to a file. If a list of columns is specified, COPY will only copy the data in the specified columns to or from the file. COPY TO copies the contents of a table to a file, whileĬOPY FROM copies data from a file to a table (appending the data to whatever is in the table already). COPY moves data between PostgreSQL tables and standard file-system files.
