<<O>>  Difference Topic FoxProToPostgreSQL (r1.1 - 20 Oct 2005 - KirkStrauser)
Line: 1 to 1
Added:
>
>
So, you want to convert some FoxPro? tables to PostgreSQL?, huh? Here's how you do it:

  1. Get my patched version of the Xbase library from http://subwiki.honeypot.net/pub/xbase64-3.1.1-kirk1.tar.gz . With luck, the Xbase folks will roll my changes into the mainstream version; I'll update the link if and when that happens.
  2. Do the usual configure/make/install. If you can guarantee that your datafiles will not change while the conversion program is running (eg you've copied them from a fileserver to a local file), consider using the --without-xbase-locking to get drastic performance improvements.
  3. Use dumprecspg to convert your FoxPro? tables into a format suitable for piping into the psql client.

dumprecspg will generate the commands necessary to create near-exact replicas of your tables. Its output looks something like:

begin;
drop table invoice;
create table invoice (div char(3), shipid integer, invid integer, xrscust char(10), bil2code char(10), typeofinv char(10), typeinv char(6), pay2addrid integer, bil2addrid integer, xrsweek char(5), invnum char(19), refnum char(25), orig_supp char(2), new_corr char(1), del_sit char(1), invamt text, invdte date, bildttm timestamp, bil char(3), chkdttm timestamp, chk char(3), cr8dttm timestamp, meth char(3), misc text, del boolean, paiddttm timestamp, bilext char(15), chkext char(15));
\copy invoice from stdin
...
...
...
\.
commit;

Note that the entire process is wrapped inside a transaction so that other clients will have access to the old data until the transaction is completed.

Indices are automatically created if you specify the columns (or expressions!) you want indexed on the command line. For example,

dumprecspg foo.dbf rowid "substr(textfield,1,4)" price

will create three indices on the new foo table: one each for the rowid and price columns, and one for the substr() expression. It tries to give each index a reasonable name, but YourMileageMayVary?

Caveats

It doesn't check that a table exists before dropping it. This causes an error in PostgreSQL? if the table doesn't exist. Workaround: create a trivial table with the same name, ala:

CREATE TABLE invoice (foo integer);

If a table has memo fields, they'll be stored in tablename.fpt. Be sure that the case matches between that table and your main .dbf table! For example, if your data table is named invoice.dbf, be sure your memo table is named invoice.fpt, not Invoice.FPT or iNvOiCe.FpT! Windows doesn't care about case. Unix isn't so liberal.

-- KirkStrauser - 20 Oct 2005

Revision -
Revision r1.1 - 20 Oct 2005 - 23:12 - KirkStrauser