X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 9A9959FB266 for ; Thu, 24 Aug 2006 20:17:13 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 46204-05 for ; Thu, 24 Aug 2006 23:16:58 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from weatherbeeta.com.au (mail.weatherbeeta.com.au [202.154.127.242]) by postgresql.org (Postfix) with SMTP id C0D4A9FB252 for ; Thu, 24 Aug 2006 20:16:56 -0300 (ADT) Received: (qmail 30171 invoked from network); 24 Aug 2006 23:16:53 -0000 X-NetworkBox-HamSign: 0101;OUT;wbeetaau1;1ce57555ca6031cc6eb89e9ea1f9c0fc; Received: from mail.weatherbeeta.com.au (HELO wb-email) (172.20.0.2)by network-box.weatherbeeta.com.au with SMTP; 24 Aug 2006 23:16:53 -0000 Received: from 172.20.0.155 ([172.20.0.155]) by wb-email (602Pro LAN SUITE 2003) id 2d5b4da1 for pgsql-sql@postgresql.org; Fri, 25 Aug 2006 9:16:50 +1000 From: "Phillip Smith" To: Subject: Re: Importing data from csv Date: Fri, 25 Aug 2006 09:16:46 +1000 Message-ID: <004a01c6c7d3$60de8320$9b0014ac@ITPhil> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_004B_01C6C827.328A9320" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6626 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 In-Reply-To: <7539aebb0608240747j6da083b2i3e1f380124504955@mail.gmail.com> Importance: Normal X-Scanned-By-wbeetaau1: Virus scan performed by network-box X-Scanned-By-wbeetaau1: Scanner file id is wbeetaau1-1156461413.32-30161-000 X-Scanned-By-wbeetaau1: No known viruses found in message (received+scanned in 0.05/0.13 secs) X-Scanned-By-wbeetaau1: Spam-Check-Result: No, hits=0 required=7 tests= autolearn=no version=2.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.818 tagged_above=0 required=5 tests=HTML_MESSAGE, SPF_HELO_SOFTFAIL, SPF_SOFTFAIL, UNPARSEABLE_RELAY X-Spam-Level: *** X-Archive-Number: 200608/191 X-Sequence-Number: 26149 This is a multi-part message in MIME format. ------=_NextPart_000_004B_01C6C827.328A9320 Content-Type: text/plain;charset="us-ascii" Content-Transfer-Encoding: quoted-printable I recently did this by parsing the data through a VB program that = appended a "\" in front of any Char(10) and/or Char(13) characters which tells = Postgres to accept the next character as a literal part of the column value I = believe - must do because it worked! I also quoted the whole column as part of = the VB prog. =20 Worked for me but I'm not sure the exact science behind it so someone = else might be able to be of some more detailed help. =20 Cheers, -p =20 -----Original Message----- From: pgsql-sql-owner@postgresql.org = [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Sumeet Sent: Friday, 25 August 2006 00:48 To: pgsql-sql@postgresql.org Subject: [SQL] Importing data from csv =20 Hi Folks, sorry if this is a duplicate post, i've been tryin to find a solution of importing data into postgres from a csv file. The problem is, I have a database which consists of columns which contain newline characters (mac = and unix). now when i export these files to a csv format, there are some = line breaks (mixed unix and mac) in the data which breaks the copy procedure. = I also tried using the script posted in one of the previous posts.. #! /usr/bin/perl $inquotes =3D 0; while (<>){ # Chop the crlf chop ($_); chop ($_); # this first bit goes through and replaces=20 # all the commas that re not in quotes with tildes for ($i=3D0 ; $i < length($_) ; $i++){ $char=3Dsubstr($_,$i,1); if ($char eq '"' ){ $inquotes =3D not($inquotes);=20 }else{ if ( (!$inquotes) && ($char eq ",") ){ substr($_,$i,1)=3D"~"; } } } # this replaces any quotes s/"//g; print "$_\n"; } cat data_file | perl scriptname.pl > outputfile.dat and when i run the copy command i get messages like data missing for xyz column. any possible hints.......=20 -- Thanks, Sumeet=20 *******************Confidentiality and Privilege Notice******************* The material contained in this message is privileged and confidential to the addressee. If you are not the addressee indicated in this message or responsible for delivery of the message to such person, you may not copy or deliver this message to anyone, and you should destroy it and kindly notify the sender by reply email. Information in this message that does not relate to the official business of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta. Weatherbeeta, its employees, contractors or associates shall not be liable for direct, indirect or consequential loss arising from transmission of this message or any attachments ------=_NextPart_000_004B_01C6C827.328A9320 Content-Type: text/html;charset="us-ascii" Content-Transfer-Encoding: quoted-printable

I recently did this by parsing the = data through a VB program that appended a “\” in front of any = Char(10) and/or Char(13) characters which tells Postgres to accept the next = character as a literal part of the column value I believe – must do because it = worked! I also quoted the whole column as part of the VB = prog…

 

Worked for me but I’m not = sure the exact science behind it so someone else might be able to be of some more detailed help.

 

Cheers,

-p

 

-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] = On Behalf Of Sumeet
Sent:
Friday, 25 August 2006 00:48
To: = pgsql-sql@postgresql.org
Subject: [SQL] Importing = data from csv

 

Hi Folks,

sorry if this is a duplicate post, i've been tryin to find a solution of importing data into postgres from a csv file. The problem is, I have a = database which consists of columns which contain newline characters (mac and = unix). now when i export these files to a csv format, there are some line breaks = (mixed unix and mac) in the data which breaks the copy procedure.

I also tried using the script posted in one of the previous posts..

#! /usr/bin/perl
$inquotes =3D 0;
while (<>){
     # Chop the crlf
     chop ($_);
     chop ($_);

     # this first bit goes through and replaces
     # all the commas that re not in  quotes = with tildes
     for ($i=3D0 ; $i < length($_) ; $i++){
         = $char=3Dsubstr($_,$i,1);
         if ($char eq '"' = ){
             $inquotes =3D not($inquotes);
         }else{
             = if ( (!$inquotes) && ($char eq ",") ){
            &= nbsp;    substr($_,$i,1)=3D"~";
             = }
         }
     }
     # this replaces any quotes
     s/"//g;
     print "$_\n";
}


cat data_file | perl scriptname.pl > outputfile.dat

and when i run the copy command i get messages like data missing for xyz column.
any possible hints.......

--
Thanks,
Sumeet


*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to the addressee. If you are not the addressee indicated in this message or responsible for delivery of the message to such person, you may not copy or deliver this message to anyone, and you should destroy it and kindly notify the sender by reply email.

Information in this message that does not relate to the official business of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta. Weatherbeeta, its employees, contractors or associates shall not be liable for direct, indirect or consequential loss arising from transmission of this message or any attachments
------=_NextPart_000_004B_01C6C827.328A9320--