Question

I use the following to load data into postgres

\copy tab FROM /tmp/file DELIMITER E'\t' QUOTE E'\b' NULL AS '\N' CSV

Usually I select the data from a source db

echo "select * from tab" | mysql --batch --quick --skip-column-names .... > /tmp/file

It generates a file with tab delimiter fields. It works well for the most part. Up until I try to import multi line text column. The error comes on:

ERROR:  unquoted carriage return found in data

Any recommendations how to overcome this?

Était-ce utile?

La solution

The mysql command you show seems (experimentally, not from actual knowledge) to generate output which is compatible with PostgreSQL's TEXT format, not the CSV format. Newlines are represented by the two characters \n, tabs by \t, and literal backslashes by \\.

So try to import it in that format, which is the default:

\copy tab FROM /tmp/file
Licencié sous: CC-BY-SA avec attribution
Non affilié à dba.stackexchange
scroll top