Sample Header Ad - 728x90

Migrating from PostgreSQL to MySQL (data with \r\n)

1 vote
2 answers
312 views
I'm trying to migrate a database from PostgreSQL to MySQL on an Ubuntu 23.04 system (latest version of both). So far, it looks like things are fine, except for one problem. In one of the character varying fields in PostgreSQL, there are \r\n characters. Yeah -- whoever developed this system made a front-end that allowed them. I'm saving the data using a command such as this:
-U mylogin --data-only --file=foo.sql --no-owner --column-inserts --table foo --quote-all-identifiers
which: - does not output the schema (I have separate CREATE TABLE statements for that) - creates only INSERT statements - does not associate an owner to the table --quote-all-identifiers was something I tried and it seems having it or not having it does not solve my problem. My problem is that I might have a row like: [1, "hello", "hello\r\nthere"] which looks like this in foo.sql: INSERT INTO TEST (id, comment1, comment2) VALUES (1, 'hello', 'hello there'); and MySQL does not like this (i.e. mysql -u mylogin -p . When doing backups and restorations within PostgreSQL, there wasn't any problem since pg_dump with default options uses COPY. I looked through the options for pg_dump and no obvious option jumps up at me that would solve this problem. I thought having a quote would (i.e., --quote-all-identifiers), but it did not. I'm not sure if I should look into how PostgreSQL is exporting it or how MySQL is importing it...or some other solution I haven't yet thought of. I was thinking of doing this on the PostgreSQL database:
TEST set comment2 = regexp_replace (description, E'([\\n\\r]+)', ' ', 'g');
(Untested) But I guess I would rather not change the source data if I can. Does anyone have a suggestion about what I should do? Or perhaps I'm going about this wrong... Thank you!
Asked by Ray (113 rep)
Sep 29, 2023, 08:44 PM
Last activity: May 15, 2025, 05:02 AM