Re: [ADMIN] How to transfer data from FoxPro data to Postgresql? - Mailing list pgsql-admin

From Thomas Good
Subject Re: [ADMIN] How to transfer data from FoxPro data to Postgresql?
Date
Msg-id Pine.LNX.3.96.980901142018.11042A-100000@mailhost.nrnet.org
Whole thread Raw
In response to How to transfer data from FoxPro data to Postgresql?  ("S.Ramaswamy" <srswamy@giasdl01.vsnl.net.in>)
Responses Re: [ADMIN] How to transfer data from FoxPro data to Postgresql?  (eigenstr@mixi.net)
List pgsql-admin
On Tue, 1 Sep 1998, S.Ramaswamy wrote:

> We have our data now in FoxPro dbf format under DOS. We want to transfer
> this to
> Postgresql under Linux. What is the best way to do so?

Hi,

I don't know the best way ;-)

Here is what I do (this is the `clumsy way'):

Dump the query output as a dumpfile delimited by tabs.
Reformat the output for pgsql...

NOTES: FoxPro DOS gave me an EOF (^Z) that had to be stripped.
As DOS does a ^J^M dance (CRLF) these embedded chars must also be
stripped. The /         / bit in the script below was to rm any bad date
values - making them proper NULLs.  The empty date placeholders must
be nulled BEFORE you strip away the double quotes otherwise char strs
end up with embedded nulls.  ;-)

Next the double quote FoxPro nulls ( "" ) are converted to proper
NULLs.  Lastly, the surviving quotes are stripped.

IMPORTANT: the ^Z and ^M are _literals_.  I edit them into the script
with i, ^V, ^M  (in vi...)

#!/bin/sh
tput clear
echo -n "Enter file to be converted: "
read file
sed -e '/^Z/d' $file > $file.step0
sed -e 's/^M//g' $file.step0 > $file.step1
sed -e 's/        /\\N/g' $file.step1 > $file.step2
sed -e 's/""/\\N/g' $file.step2 > $file.step3
sed -e 's/"//g' $file.step3 > $file.pg
rm $file.step0
rm $file.step1
rm $file.step2
rm $file.step3

After this, add
COPY table_name FROM stdin;
to the top of your dumpfile.

And
\.
to the end.

Then run:
psql -e db_name < dumpfile_name

BTW, if you have questions, fire away.  All of us FoxPro victims must
stick together!  (I recommend a pint of bitter be kept handy during the
process of hacking the foxpro psuedo-sql into postgres ;-)

Cheers,
Tom

    ----------- Sisters of Charity Medical Center ----------
                    Department of Psychiatry
                              ----
 Thomas Good, System Administrator            <tomg@q8.nrnet.org>
 North Richmond CMHC/Residential Services     Phone: 718-354-5528
 75 Vanderbilt Ave, Quarters 8                Fax:   718-354-5056
 Staten Island, NY   10304                    www.panix.com/~ugd
                              ----
 Powered by PostgreSQL 6.3.2 / Perl 5.004 / DBI-0.91::DBD-PG-0.69


pgsql-admin by date:

Previous
From: "S.Ramaswamy"
Date:
Subject: How to transfer data from FoxPro data to Postgresql?
Next
From: eigenstr@mixi.net
Date:
Subject: Re: [ADMIN] How to transfer data from FoxPro data to Postgresql?