Received: from www.wgcr.org (www.wgcr.org [206.74.232.194]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f0IKmM007045 for ; Thu, 18 Jan 2001 15:48:22 -0500 (EST) (envelope-from lamar.owen@wgcr.org) Received: from wgcr.org ([10.1.2.1]) by www.wgcr.org (8.9.3/8.9.3/WGCR) with ESMTP id PAA13188; Thu, 18 Jan 2001 15:48:19 -0500 Message-ID: <3A67568B.59572A40@wgcr.org> Date: Thu, 18 Jan 2001 15:48:11 -0500 From: Lamar Owen X-Mailer: Mozilla 4.73 [en] (Win95; U) X-Accept-Language: en MIME-Version: 1.0 To: mike CC: pgsql-interfaces@postgresql.org Subject: Re: imorting csv files into postgres References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200101/205 X-Sequence-Number: 823 mike wrote: > Does anyone know if you can import csv text files into postgres A perl script to do that was just posted to the GENERAL List.... Hmmmm.... Tim Uckun just posted the following: ------- Here is your steps. 1) Create your destination table in postgres 2) Export your data to a comma delimeted format 3) save this perl script to a file ------ #! /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"; } ----- 4) type this cat myfile.txt | perl myprog.pl > outfile.dat 5) go to psql 6) COPY "tablename" FROM '/path/to/outfile.dat' USING DELIMITERS '~'; ----- See if that helps any. -- Lamar Owen WGCR Internet Radio 1 Peter 4:11