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 A3C9C9FB24D for ; Thu, 24 Aug 2006 21:20:29 -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 64716-04 for ; Fri, 25 Aug 2006 00:20:08 +0000 (UTC) X-Greylist: delayed 00:22:49.283055 by SQLgrey- Received: from pop05.mail.atl.earthlink.net (pop05.mail.atl.earthlink.net [207.69.200.58]) by postgresql.org (Postfix) with ESMTP id 4A79B9FA646 for ; Thu, 24 Aug 2006 21:20:07 -0300 (ADT) Received: from nc-71-51-254-71.dhcp.embarqhsd.net ([71.51.254.71] helo=flossware.homelinux.org) by pop05.mail.atl.earthlink.net with esmtp (Exim 3.36 #1) id 1GGPQW-0002Ue-00; Thu, 24 Aug 2006 20:20:00 -0400 Received: from [192.168.168.6] (devserver.flossware.com [192.168.168.6]) by flossware.homelinux.org (Postfix) with ESMTP id D1EC721A80D; Thu, 24 Aug 2006 20:19:58 -0400 (EDT) Message-ID: <44EE422E.8070207@mindspring.com> Date: Thu, 24 Aug 2006 20:19:58 -0400 From: "Scot P. Floess" Reply-To: floess@mindspring.com User-Agent: Thunderbird 1.5.0.4 (X11/20060516) MIME-Version: 1.0 To: Phillip Smith CC: pgsql-sql@postgresql.org Subject: Re: Importing data from csv References: <000501c6c7da$15a01b10$9b0014ac@ITPhil> In-Reply-To: <000501c6c7da$15a01b10$9b0014ac@ITPhil> Content-Type: multipart/alternative; boundary="------------060102050906020300070001" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.952 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, HTML_MESSAGE, SPF_HELO_SOFTFAIL, SPF_SOFTFAIL X-Spam-Level: *** X-Archive-Number: 200608/195 X-Sequence-Number: 26153 This is a multi-part message in MIME format. --------------060102050906020300070001 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Well, being that there isn't a RFC for CSV...other than "defacto" definitions...I am pretty sure that is widely agreed upon ;) Phillip Smith wrote: > > There you go -- it was the quotes that did it, not the back-slashes. I > knew someone else would shed some better light! J > > > > Cheers, > > -p > > > > -----Original Message----- > *From:* pgsql-sql-owner@postgresql.org > [mailto:pgsql-sql-owner@postgresql.org] *On Behalf Of *Scot P. Floess > *Sent:* Friday, 25 August 2006 10:00 > *To:* floess@mindspring.com > *Cc:* Phillip Smith; pgsql-sql@postgresql.org > *Subject:* Re: [SQL] Importing data from csv > > > > And if its contained with quotes...its considered a field > > Scot P. Floess wrote: > > A newline in CSV parlance denotes the end of a record....unless that > newline is contained with quotes... > > Phillip Smith wrote: > > 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 = 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=0 ; $i < length($_) ; $i++){ > $char=substr($_,$i,1); > if ($char eq '"' ){ > $inquotes = not($inquotes); > }else{ > if ( (!$inquotes) && ($char eq ",") ){ > substr($_,$i,1)="~"; > } > } > } > # 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 > > > > -- > Scot P. Floess > 27 Lake Royale > Louisburg, NC 27549 > > 252-478-8087 (Home) > 919-754-4592 (Work) > > Chief Architect JPlate http://sourceforge.net/projects/jplate > Chief Architect JavaPIM http://sourceforge.net/projects/javapim > > > > > -- > Scot P. Floess > 27 Lake Royale > Louisburg, NC 27549 > > 252-478-8087 (Home) > 919-754-4592 (Work) > > Chief Architect JPlate http://sourceforge.net/projects/jplate > Chief Architect JavaPIM http://sourceforge.net/projects/javapim > > ********************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 > -- Scot P. Floess 27 Lake Royale Louisburg, NC 27549 252-478-8087 (Home) 919-754-4592 (Work) Chief Architect JPlate http://sourceforge.net/projects/jplate Chief Architect JavaPIM http://sourceforge.net/projects/javapim --------------060102050906020300070001 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Well, being that there isn't a RFC for CSV...other than "defacto" definitions...I am pretty sure that is widely agreed upon ;)

Phillip Smith wrote:

There you go – it was the quotes that did it, not the back-slashes. I knew someone else would shed some better light! J

 

Cheers,

-p

 

-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Scot P. Floess
Sent: Friday, 25 August 2006 10:00
To: floess@mindspring.com
Cc: Phillip Smith; pgsql-sql@postgresql.org
Subject: Re: [SQL] Importing data from csv

 

And if its contained with quotes...its considered a field

Scot P. Floess wrote:

A newline in CSV parlance denotes the end of a record....unless that newline is contained with quotes...

Phillip Smith wrote:

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 = 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=0 ; $i < length($_) ; $i++){
         $char=substr($_,$i,1);
         if ($char eq '"' ){
             $inquotes = not($inquotes);
         }else{
             if ( (!$inquotes) && ($char eq ",") ){
                 substr($_,$i,1)="~";
             }
         }
     }
     # 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



-- 
Scot P. Floess
27 Lake Royale
Louisburg, NC  27549
 
252-478-8087 (Home)
919-754-4592 (Work)
 
Chief Architect JPlate  http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim
  



-- 
Scot P. Floess
27 Lake Royale
Louisburg, NC  27549
 
252-478-8087 (Home)
919-754-4592 (Work)
 
Chief Architect JPlate  http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim

*******************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


-- 
Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-754-4592 (Work)

Chief Architect JPlate  http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim
--------------060102050906020300070001--