Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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)
share|improve this answer
    
could you point me to any tutorials on how to do this? –  Aly Mar 9 '10 at 14:50
    
Accessing databases in python is fairly easy, since there is a standard interface (DBI). I editing the answer for more info. –  Dan Andreatta Mar 11 '10 at 9:45
add comment

.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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.