Re: Re: MS Access data to PostgrSQL data - Mailing list pgsql-general

From Tim Uckun
Subject Re: Re: MS Access data to PostgrSQL data
Date
Msg-id 5.0.0.25.2.20010118125131.023f8ed8@mail.diligence.com
Whole thread Raw
In response to MS Access data to PostgrSQL data  (Robert Korteweg <robert@bit.nl>)
List pgsql-general
>>hi,
>>can anyone help me ? i need to convert a ms access .mdb file into
>>somthing readable so i can insert it into my postgreSQL db...
>>does anyone have any experiance? (preferably using PHP)
>>Robert Korteweg
>>The Netherlands

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 '~';

you can even automate this with a VB script.



pgsql-general by date:

Previous
From: "Mikheev, Vadim"
Date:
Subject: RE: Troubles with performances
Next
From: Warren Vanichuk
Date:
Subject: RE: Troubles with performances