Trying to load MySQL data

From: "garrettmoore(at)gmail(dot)com" <garrettmoore(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Trying to load MySQL data
Date: 2007-01-10 01:54:03
Message-ID: 1168394043.437329.181580@o58g2000hsb.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I am working on a project where we are converting from MySQL to
Postgres. I figured the easiest way would be to export the MySQL data
as CSV.

I'm having a problem importing some of the data. What I have done is
exported the MySQL data and then modified it so that all single quotes
(a ' quote) are doubled, and null values are replaced with an empty
value in the CSV.

Our data, for example, looks like this:

2628,'Poster,5,'255.255.18.138',,'[quote=gz]I''m curious, why not allow
users, then to freely edit topics?[/quote]
We could either go with "it''s a minor annoyance that is one measure
that helps keep DB load lower," or "we do it just to piss you off."
You choose.',0,1124498148,,,376,0,0,,

This row causes an error. The error is that:

The value "why not allow users" is not valid for column 'x'.

Column x is the first column after the long section of text, with a
value of '0'.

It appears that the quote in "I'm", which has been doubled quoted to
'', is not being properly skipped over, and COPY thinks that the next
comma (after "curious") is a new column, and tries to start inserting
data there. At least that's what I have come up with.

Why is this happening? I've used this method before and I didn't have
any trouble, when loading a bunch of Wikipedia test data (which has all
manner of quotes, commas, and apostrophes in it).

This is line 39150 in the file; all previous lines import fine, but
this kills the COPY process and all of the previous inserts are rolled
back. I need to get this data loaded intact.

My copy command is
COPY posts FROM '/tmp/posts.txt' CSV QUOTE $$'$$;

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-01-10 05:12:49 Re: index creation on 7.3
Previous Message chwy_nougat 2007-01-10 01:06:34 remove embedded carriage returns