1

I rewrite a program based on the old Foxbase database consisting of files .dbf. I need a tool that would read these files, and helped in the transfer of data to PostgreSQL. You know maybe some of this type of tool?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
BKl
  • 415
  • 1
  • 8
  • 23
  • You could write one fairly easily with this information http://www.dbf2002.com/dbf-file-format.html – Hugh Jones Nov 07 '11 at 15:40
  • @HughJones It isn't as clear-cut as you'd hope. There are plenty of weird edge cases depending on which program generated the files. For instance, some flavors of DBF use binary coded decimals for numeric fields and memo file offsets where others use ints. There's also a nasty mix of big and little endian numbers. – Kirk Strauser Dec 30 '11 at 22:46

2 Answers2

2

pgdbf.sourceforge.net - has worked for all the DBF I've fed it. Quoting the site description:

PgDBF is a program for converting XBase databases - particularly FoxPro tables with memo files - into a format that PostgreSQL can directly import. It's a compact C project with no dependencies other than standard Unix libraries.

If you are looking for something to run on Windows, and this doesn't compile directly, you could use cygwin (www.cygwin.com) to build and run pgdbf.

j_e_f_f__k
  • 21
  • 1
  • Does it actually work to run it under Cygwin? I don't know why it wouldn't, but it'd be cool if it does! (I wrote PgDBF.) – Kirk Strauser Dec 30 '11 at 22:41
1

As part of the migration path you could use Python and my dbf module. A very simple script to convert the dbf files to csv would be:

import sys
import dbf
dbf.export(sys.argv[1])

which will create a .csv file of the same name as the dbf file. If you put that code into a script named dbf2csv.py you could then call it as

python dbf2csv.py dbfname

Hopefully there are some handy tools to get the csv file into PostgreSQL.

Ethan Furman
  • 63,992
  • 20
  • 159
  • 237