我有几个DB,我可以通过pgAdmin 3访问,我有一个只能分析.mdb文件的软件。 有没有人知道如何转换/导出一个PostgreSQL数据库到Mdb? 最好通过pgAdmin 3?
谢谢
您应该能够使用ODBC使用MS Access文件(如果您有一个窗口框可用)。 有了这个,你可以编写一个小脚本来将数据库从一种格式转储到另一种格式,例如使用obdc,pyodbc或mxODBC软件包。
一个简单的例子可以(在Windows上运行,没有真正的testing,你可能需要下载psycopg2软件包):
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)
.MDB是MS Access,对不对? 我怀疑pgAdmin 3能够做到这一点。 如果Access可以处理SQL,那么你可以将Postgres数据库转换为纯文本SQL,并将其加载到Access中(只需稍作更改,我猜测)。 如果没有,那么你可能不得不写一个从Postgres读取并写入Access / MDB的小程序。 也许已经存在一个。 我发现使用Google的大多数转换器都是朝另一个方向发展。