Re: Export tab delimited from mysql to postgres.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Theo Galanakis <Theo(dot)Galanakis(at)lonelyplanet(dot)com(dot)au>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Export tab delimited from mysql to postgres.
Date: 2004-10-12 13:56:15
Message-ID: 1763.1097589375@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Theo Galanakis <Theo(dot)Galanakis(at)lonelyplanet(dot)com(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Johann Robette 2004-10-12 15:54:41 JDBC +CIDR
Previous Message Markus Bertheau 2004-10-12 13:41:15 Re: PL/pgSQL, RETURN NEXT, ORDER