通过ODBC将Excel连接到PostgreSQL

我试图通过PostgreSQL ODBC 32位驱动程序从Excel连接到PostgreSQL数据库表.

在Excel中,我转到数据>获取数据>来自其他来源>来自ODBC.我导航到我设置的ODBC数据源,输入凭据,并在显示可用表时清楚地连接.当我点击“加载”给出错误时,预览失败并且查询失败:

DataSource.Error: ODBC: ERROR [HY000] Error while executing the query
Details:
    DataSourceKind=Odbc
    DataSourcePath=dsn=PostgreSQL
    OdbcErrors=Table

《通过ODBC将Excel连接到PostgreSQL》

当我在ODBC管理中测试连接时,它是成功的.我已经尝试过ANSI和Unicode驱动程序. TIBCO Spotfire连接到ODBC数据源并将数据拉得很好.

您将提供的任何帮助将不胜感激.

最佳答案 这似乎是最新的psqlODBC驱动程序的错误,在我写这篇文章的时候是psqlodbc_09_06_0500.我可以访问我的PostgreSQL服务器日志.这是错误消息和违规查询:

ERROR:  syntax error at or near "ta" at character 553
STATEMENT:  select ta.attname, ia.attnum, ic.relname, n.nspname, tc.relname from pg_catalog.pg_attribute ta, pg_catalog.pg_attribute ia, pg_catalog.pg_class tc, pg_catalog.pg_index i, pg_catalog.pg_namespace n, pg_catalog.pg_class ic where tc.relname = 'rates' AND n.nspname = 'public' AND tc.oid = i.indrelid AND n.oid = tc.relnamespace AND i.indisprimary = 't' AND ia.attrelid = i.indexrelid AND ta.attrelid = i.indrelid AND ta.attnum = i.indkey[ia.attnum-1] AND (NOT ta.attisdropped) AND (NOT ia.attisdropped) AND ic.oid = i.indexrelid order by ia.attnumselect ta.attname, ia.attnum, ic.relname, n.nspname, NULL from pg_catalog.pg_attribute ta, pg_catalog.pg_attribute ia, pg_catalog.pg_class ic, pg_catalog.pg_index i, pg_catalog.pg_namespace n where ic.relname = 'rates_pkey' AND n.nspname = 'public' ANDic.oid = i.indexrelid AND n.oid = ic.relnamespace AND ia.attrelid = i.indexrelid AND ta.attrelid = i.indrelid AND ta.attnum = i.indkey[ia.attnum-1] AND (NOT ta.attisdropped) AND (NOT ia.attisdropped) order by ia.attnum

这是围绕角色553的上下文:依次为ia.attnumselect ta.attname,ia.attnum.请注意,它缺少两个字段名称之间的逗号.

我能够使用大约一年的psqlodbc_09_06_0200.由于听起来您使用的是32位Office,因此可以从https://www.postgresql.org/ftp/odbc/versions/msi/下载psqlodbc_09_06_0200-x86.zip.(如果安装了64位Office,请使用x64.)

您可以在psqlodbc_09_06_0200-x86.zip和psqlodbc_09_06_0500-x86.zip之间尝试驱动程序版本,因为可能是在这两个版本之间引入了错误.

点赞