Re: Export tab delimited from mysql to postgres. - Mailing list pgsql-sql

From Tom Lane
Subject Re: Export tab delimited from mysql to postgres.
Date
Msg-id 1763.1097589375@sss.pgh.pa.us
Whole thread Raw
In response to Re: Export tab delimited from mysql to postgres.  (Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au>)
List pgsql-sql
Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au> writes:
> As you can see row 2 has a value that holds a CR value which ends up
> wrapping around onto the third line. Postgres copy command does not like
> this and mysql is unable to replace the value with another type of
> delimiter, like a \r.

> So I gather I have to some how manually replace the carriage return with
> something postgres understand \r...

> columnA    columnB
> 1        What a day!
> 2        What a week it has \r been!
> 3        What the!

> How do I do this without getting a text file that looks like this
> 1    What a day! \r\n2        What a week it has \r been!\r\n3
> What the!\r\n

Looks like a simple sed problem to me:
cat myfile | sed 's/\r$//' | sed 's/\r/\\r/g' >newfile

(Most likely you can do both steps in one sed process, but this is easy
to follow.)  This assumes that you only have newlines (\n) at the real
ends of lines, else you need to think harder about how to tell the
difference between data and formatting.
        regards, tom lane


pgsql-sql by date:

Previous
From: Markus Bertheau
Date:
Subject: Re: PL/pgSQL, RETURN NEXT, ORDER
Next
From: "Johann Robette"
Date:
Subject: JDBC +CIDR