By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 697 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

How to process new line in fields while copying data from a file using COPY command

P: 1
Hi,In my migration script while I am using mysqldump to dump my MySQL database and PostgreSQL COPY command to copy the data files to PostgreSQL db, I am getting error cause of the newline in the fields

Mysqldump command:
Mysqldump –u username -p --no-create-info
--skip-triggers --skip-comments --fields-terminated-by =,
--lines-terminated-by=\n –TC:\tmp –r UTF8 dbname

PostgreSQL COPY command:

COPY dbname.tablename from
‘c:\tmp\tablename.txt’ WITH DELIMITER ‘,’ CSV
NULL ‘\N’ ;But I get the error-
literal carriage return found in data
hint: use \r to represent carriage return
context: COPY tablename line 52
I checked line 52, it has new line in one of the field data
I know I can postprocess the files that are created by mysqldump, but was wondering is there any way to handle it within the postgreSQL COPY command so it escapes the new line within field data?*
Sep 13 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.