mysql - error using copy from in postgresql when value is '2"%' -


i have table 300,000 rows not under control need import.

i export data mysql using:

mysqldump -u root --password=secret --fields-enclosed-by='\"' -t/tmp apflora_beob 

then try import each table using example:

\copy beob_evab '/users/alex/tmp/beob_evab.txt' (format 'csv', delimiter e'\t', null '\n', escape e'\"', encoding 'utf8'); 

this works tables, 1 containing 450,000 rows. on 1 error:

error:  value long type character varying(10) context:  copy beob_evab, line 190310, column couv_mousses: "2\%  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  30  \n  15  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  0.01  \n  \n bachs, dau..." 

when check field couv_mousses in line 190'310 contains value: 2"%.

what have change work?

in order achieve correct output "2""%" according @klin (thanks!) have add --fields-escaped-by='"' mysqldump command. becomes:

mysqldump -u root --password=secret --fields-enclosed-by='"' --fields-escaped-by='"' -t/tmp apflora_beob 

problem is: null values exported "n.

well, no problem, thought , changed copy command to:

\copy beob_evab '/users/alex/tmp/beob_evab.txt' (format 'csv', delimiter e'\t', null '"n', escape "'", encoding 'utf8'); 

this produces following error in postgres:

error:  csv quote character must not appear in null specification 

and seems representation of null values can not changed in mysql.

the value should written down

"2""%" 

per rfc 4180 - common format , mime type comma-separated values (csv) files:

[5]. each field may or may not enclosed in double quotes (however programs, such microsoft excel, not use double quotes @ all). if fields not enclosed double quotes, double quotes may not appear inside fields.(...)

[7]. if double-quotes used enclose fields, double-quote appearing inside field must escaped preceding double quote. example:

   "aaa","b""bb","ccc" 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -