Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 63A554761EB for ; Wed, 29 Jan 2003 01:59:37 -0500 (EST) Received: from email06.aon.at (WARSL401PIP3.highway.telekom.at [195.3.96.75]) by postgresql.org (Postfix) with SMTP id 243CE479D2D for ; Wed, 29 Jan 2003 00:54:40 -0500 (EST) Received: (qmail 376074 invoked from network); 29 Jan 2003 05:54:45 -0000 Received: from m214p001.dipool.highway.telekom.at (HELO aon.at) ([62.46.16.161]) (envelope-sender ) by qmail6rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 29 Jan 2003 05:54:45 -0000 Message-ID: <3E376BB2.4010302@aon.at> Date: Wed, 29 Jan 2003 06:50:42 +0100 From: Oliver Vecernik User-Agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.0.0) Gecko/20020623 Debian/1.0.0-0.woody.1 X-Accept-Language: de, de-de MIME-Version: 1.0 To: pgsql-sql Subject: Re: CSV import References: <3E3697AF.2030509@aon.at> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/470 X-Sequence-Number: 11335 Oliver Vecernik schrieb: > Hi again! > > After investigating a little bit further my CSV import couldn't work > because of following reasons: > > 1. CSV files are delimited with CR/LF > 2. text fields are surrounded by double quotes > > Is there a direct way to import such files into PostgreSQL? The answer seems to be no. But after googeling a bit a found a wonderful Python module called csv at: http://www.object-craft.com.au/projects/csv/ A minimal script called 'csv2tab.py' for conversion to a tab delimited file could be: #!/usr/bin/env python import csv import sys def convert(file): try: f = open(file, 'r') lines = f.readlines() p = csv.parser() for line in lines: print '\t'.join(p.parse(line)) except: print 'Error opening file!' if __name__ == '__main__': convert(sys.argv[1]); Regards, Oliver -- VECERNIK Datenerfassungssysteme A-2560 Hernstein, Hofkogelgasse 17 Tel.: +43 2633 47530, Fax: DW 50 http://members.aon.at/vecernik