I would like to use the psql "\copy" command to pull data from a tab-delimited file into Postgres. I'm using this command:
\copy cm_state from 'state.data' with delimiter '\t' null as ;
But I'm getting this warning (the table actually loads fine):
WARNING: nonstandard use of escape in a string literal LINE 1: COPY cm_state FROM STDIN DELIMITER '\t' NULL AS ';' HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
How do I specify a tab if '\t' is not correct?
The delimiter is a string used as the delimiter for splitting. The position argument sets the part of the string that is to be returned, starting from 1. The argument must have a positive integer as its value.
Psql \copy command is used when you want to export the data from Postgres table to a CSV file on a client machine. To use this command, you will need access to the psql prompt. You will understand it more with the following psql copy examples. To copy the entire table to a csv file, use \copy.
To copy a table with partial data from an existing table, users can use the following statement: Syntax: CREATE TABLE new_table AS SELECT * FROM existing_table WHERE condition; The condition in the WHERE clause of the query defines which rows of the existing table will be copied to the new table.
You can provide the columns your want to fill with the COPY command. Like so: \copy your_table (x2,x5,x7,x10) FROM '/path/to/your-file.
Use E'\t'
to tell postgresql there may be escaped characters in there:
\copy cm_state from 'state.data' with delimiter E'\t' null as ';'
you can do this copy cm_state from stdin with (format 'text')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With