X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B3E37329E25 for ; Tue, 12 Oct 2004 06:38:08 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 95390-08 for ; Tue, 12 Oct 2004 05:37:58 +0000 (GMT) Received: from www.postgresql.com (www.postgresql.com [200.46.204.209]) by svr1.postgresql.org (Postfix) with ESMTP id BF8A8329E57 for ; Tue, 12 Oct 2004 06:37:58 +0100 (BST) Received: from angel.lonelyplanet.com.au (mail.lonelyplanet.com.au [202.147.44.168]) by www.postgresql.com (Postfix) with ESMTP id 85FDB5A107E for ; Tue, 12 Oct 2004 06:37:53 +0100 (BST) Received: from shiva.au.lpint.net ([192.168.61.22]) by angel with InterScan Messaging Security Suite; Tue, 12 Oct 2004 15:33:24 +1000 Received: by shiva.au.lpint.net with Internet Mail Service (5.5.2656.59) id <4VK6XV3H>; Tue, 12 Oct 2004 15:33:48 +1000 Message-ID: <82E30406384FFB44AFD1012BAB230B5505F40D43@shiva.au.lpint.net> From: Theo Galanakis To: pgsql-sql@postgresql.org Subject: Re: Export tab delimited from mysql to postgres. Date: Tue, 12 Oct 2004 15:33:46 +1000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2656.59) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C4B01D.0B865670" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.0 tagged_above=0.0 required=5.0 tests=DNS_FROM_RFCI_DSN, EXCUSE_16, HTML_20_30, HTML_MESSAGE X-Spam-Level: ** X-Archive-Number: 200410/80 X-Sequence-Number: 19183 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C4B01D.0B865670 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks for all your comments, I have beent trying the insert within a transaction block, however it does not seem to reduce the time it takes to process each records. Mind you there are 80 column and the insert statement explicitly defines the column to insert into. I need any tip I can get help me transform the text file into a format postgres copy will successfully read.=0D Here is sample of the current format of a mysql tab delimited dump.. columnA columnB=0D 1 What a day! 2 What a week it has been! 3 What the! 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...=0D columnA columnB=0D 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=0D 1 What a day! \r\n2 What a week it has \r been!\r\n3 What the!\r\n Any help would be appreciated. Theo -----Original Message----- From: Christopher Browne [mailto:cbbrowne@acm.org]=0D Sent: Tuesday, 12 October 2004 10:46 AM To: pgsql-sql@postgresql.org Subject: Re: [SQL] Export tab delimited from mysql to postgres. Quoth Theo.Galanakis@lonelyplanet.com.au (Theo Galanakis): > =A0=A0=A0=A0=A0=A0=A0 Could you provide a example of how to do this? > > =A0=A0=A0=A0=A0=A0=A0 I actually ended up exporting the data as Insert st= atements, > which strips out cf/lf within varchars. However it takes an eternity=0D > to import 200,000 records... 24 hours infact???? Is this normal? I expect that this results from each INSERT being a separate transaction. If you put a BEGIN at the start and a COMMIT at the end, you'd doubtless see an ENORMOUS improvement. That's not even the _big_ improvement, either. The _big_ improvement would involve reformatting the data so that you could use the COPY statement, which is _way_ faster than a bunch of INSERTs. Take a look at the documentation to see the formatting that is needed: http://techdocs.postgresql.org/techdocs/usingcopy.php http://www.faqs.org/docs/ppbook/x5504.htm http://www.postgresql.org/docs/7.4/static/sql-copy.html --=0D output =3D ("cbbrowne" "@" "ntlug.org") http://www3.sympatico.ca/cbbrowne/lsf.html Question: How many surrealists does it take to change a light bulb? Answer: Two, one to hold the giraffe, and the other to fill the bathtub with brightly colored machine tools. ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) ______________________________________________________________________ This email, including attachments, is intended only for the addressee and may be confidential, privileged and subject to copyright. If you have received this email in error, please advise the sender and delete it. If you are not the intended recipient of this email, you must not use, copy or disclose its content to anyone. You must not copy or=0D communicate to others content that is confidential or subject to=0D copyright, unless you have the consent of the content owner.= ------_=_NextPart_001_01C4B01D.0B865670 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable RE: [SQL] Export tab delimited from mysql to postgres.

Thanks for all your comments,

        I have beent t= rying the insert within a transaction block, however it does not seem to re= duce the time it takes to process each records. Mind you there are 80 colum= n and the insert statement explicitly defines the column to insert into.

        I need any tip= I can get help me transform the text file into a format postgres copy will= successfully read.

Here is sample of the current format of a mysql tab delim= ited dump..

columnA columnB
1          =      What a day!
2          =      What a week it has
been!
3          =      What the!

As you can see row 2 has a value that holds a CR value wh= ich 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 o= f delimiter, like a \r.

So I gather I have to some how manually replace the carri= age 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 l= ike this
1       What a day! \r\n2&= nbsp;            &nb= sp; What a week it has \r been!\r\n3      &nb= sp;         What the!\r\n

Any help would be appreciated.

Theo

-----Original Message-----
From: Christopher Browne [mailto:cbbrowne@acm.org]
Sent: Tuesday, 12 October 2004 10:46 AM
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] Export tab delimited from mysql to po= stgres.


Quoth Theo.Galanakis@lonelyplanet.com.au (Theo Galanakis)= :
> =A0=A0=A0=A0=A0=A0=A0 Could you provide a example o= f how to do this?
>
> =A0=A0=A0=A0=A0=A0=A0 I actually ended up exporting= the data as Insert statements,
> which strips out cf/lf within varchars. However it = takes an eternity
> to import 200,000 records... 24 hours infact???? Is= this normal?

I expect that this results from each INSERT being a separ= ate transaction.

If you put a BEGIN at the start and a COMMIT at the end, = you'd doubtless see an ENORMOUS improvement.

That's not even the _big_ improvement, either.  The = _big_ improvement would involve reformatting the data so that you could use= the COPY statement, which is _way_ faster than a bunch of INSERTs.  T= ake a look at the documentation to see the formatting that is needed:

http://techdocs.postgresql.org/techdocs/usingcop= y.php
http://www.faqs.org/docs/ppbook/x5504.htm
http://www.postgresql.org/docs/7.4/static/sql= -copy.html
--
output =3D ("cbbrowne" "@" "ntl= ug.org") http://www3.sympatico.ca/cbbrowne/lsf.html
Question: How many surrealists does it take to change a = light bulb?

Answer: Two, one to hold the giraffe, and the other to fi= ll the bathtub
        with brightly= colored machine tools.

---------------------------(end of broadcast)------------= ---------------
TIP 2: you can get off all lists at once with the unregi= ster command
    (send "unregister YourEmailAddre= ssHere" to majordomo@postgresql.org)

____________________= __________________________________________________
This email, including= attachments, is intended only for the addressee
and may be confidential= , privileged and subject to copyright. If you
have received this email = in error, please advise the sender and delete
it. If you are not the in= tended recipient of this email, you must not
use, copy or disclose its c= ontent to anyone. You must not copy or
communicate to others content t= hat is confidential or subject to
copyright, unless you have the consen= t of the content owner.
= ------_=_NextPart_001_01C4B01D.0B865670--