Re: Re: MS Access data to PostgrSQL data

From: Tim Uckun <tim(at)diligence(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Re: MS Access data to PostgrSQL data
Date: 2001-01-18 19:59:48
Message-ID: 5.0.0.25.2.20010118125131.023f8ed8@mail.diligence.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Warren Vanichuk 2001-01-18 20:04:44 RE: Troubles with performances
Previous Message Yohans Mendoza 2001-01-18 19:29:00 character sets