2

I have a few DB's which I can access through pgAdmin 3, I have a piece of software that can only analyze .mdb files. does anyone know how to convert/export a postgres db to a mdb? preferably through pgAdmin 3?

Thanks

2 Answers 2

2

You should be able to use MS Access files using ODBC (if you have a windows box available). With that you can write a small script to dump the database from one format to the other, e.g. with python using obdc, pyodbc or mxODBC packages.

a simple example can be (running on windows, not really tested, you will need to download the psycopg2 package, probably):

import odbc, psycopg2

odbc_conn = odbc.odbc("DSN=MY_ACCESS_DATABASE")
pg_conn = psycopg2.connect("host=server_name dbname=my_db user=godot password=???")

pg_curs = pg_conn.cursor()
odbc_curs = odbc_conn.cursor()

pg_curs.execute('select * from my_table')
for row in pg_curs.fetchall():
    # The format depends on your table, of course
    # With more work you can make it more generic, generating the 
    # format string from the type of the columns
    odbc_curs.execute('insert into my_table values (%s,%d,%d)' % row)
2
  • could you point me to any tutorials on how to do this?
    – Aly
    Mar 9, 2010 at 14:50
  • Accessing databases in python is fairly easy, since there is a standard interface (DBI). I editing the answer for more info. Mar 11, 2010 at 9:45
0

.MDB is MS Access, right? I doubt pgAdmin 3 being able to do that. If Access can handle SQL then you can probably dump the Postgres databases to plain text SQL and load it into Access (with small changes, I'm guessing). If not, then you probably have to write a small program that reads from Postgres and writes to Access/MDB. Maybe there exists one already. Most converters I found using Google go in the other direction.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .