pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sumeet <asumeet@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Importing data from csv
Date: Thu, 24 Aug 2006 10:47:57 -0400
Message-ID: <7539aebb0608240747j6da083b2i3e1f380124504955@mail.gmail.com> (raw)

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

view thread (8+ messages)  latest in thread

Message-ID: <7539aebb0608240747j6da083b2i3e1f380124504955@mail.gmail.com>
Permalink:  ../7539aebb0608240747j6da083b2i3e1f380124504955@mail.gmail.com/
Also on:    postgresql.org/message-id/7539aebb0608240747j6da083b2i3e1f380124504955@mail.gmail.com

 · 

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: asumeet@gmail.com
  Subject: Re: Importing data from csv
  In-Reply-To: <7539aebb0608240747j6da083b2i3e1f380124504955@mail.gmail.com>

* 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