pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: Export tab delimited from mysql to postgres.
Date: Tue, 12 Oct 2004 09:56:15 -0400
Message-ID: <1763.1097589375@sss.pgh.pa.us> (raw)
In-Reply-To: <82E30406384FFB44AFD1012BAB230B5505F40D43@shiva.au.lpint.net>
References: <82E30406384FFB44AFD1012BAB230B5505F40D43@shiva.au.lpint.net>

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



view thread (9+ messages)  latest in thread

Message-ID: <1763.1097589375@sss.pgh.pa.us>
Permalink:  ../1763.1097589375@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1763.1097589375@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Theo.Galanakis@lonelyplanet.com.au
  Subject: Re: Export tab delimited from mysql to postgres.
  In-Reply-To: <1763.1097589375@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox