Postgresql 外部数据包装器在从 SQL Server 检索任何外部表数据时引发错误


我使用 freetds 在 postgresql 中设置了外部数据

包装器以连接到 SQL Server,并在 postgresql 中安装了 tds_fdw 扩展,但是当从外部表中选择数据时,代码总是引发以下数据库库错误:

DB #: 4075 错误:
USE 数据库语句失败,因为较旧的客户端驱动程序无法识别数据库排序规则Persian_100_CI_AI。尝试升级客户端操作系统或将服务更新应用于数据库客户端软件,或使用其他排序规则。有关更改排序规则的详细信息,请参阅 SQL Server 联机丛书

我深入研究了位于/etc/freetds的网络和配置freets.conf文件

[global]
        # TDS protocol version
;       tds version = 8.0
        # Whether to write a TDSDUMP file for diagnostic purposes
        # (setting this to /tmp is insecure on a multi-user system)
;       dump file = /tmp/freetds.log
;       debug flags = 0xffff
        # Command and connection timeouts
;       timeout = 10
;       connect timeout = 10
        # If you get out-of-memory errors, it may mean that your client
        # is trying to allocate a huge buffer for a TEXT field.
        # Try setting 'text size' to a more reasonable limit
        text size = 64512
        client charset = UTF-8
# A typical Sybase server
[egServer50]
        host = symachine.domain.com
        port = 5000
        tds version = 5.0
# A typical Microsoft server
[mssql]
        host = 192.168.x.x
        port = 1433
        tds version = 7.1

这是我在 Postgres 中的 SQL 代码

CREATE SERVER prs_server
FOREIGN DATA WRAPPER tds_fdw
OPTIONS (servername '192.168.x.x', port '1433',database 'prs_bpms', tds_version '7.1', msg_handler 'notice');
CREATE USER MAPPING FOR postgres
SERVER prs_server
OPTIONS (username 'bpms', password 'xxxx');
CREATE FOREIGN TABLE prs_table (
    FirstName varchar null,
       LastName varchar nuul,
       SSN varchar not null
)
SERVER prs_server 
OPTIONS (query 'SELECT top 10 [FirstName],[LastName],[SSN] FROM [dbo].[prs_Personnel] ');

SELECT * FROM prs_table;

而且我还需要使用 where 子句,但像 'select from where ssn = '1234'' 这样的反斜杠转义字符不起作用并给出语法错误。

任何帮助将不胜感激。

根据这个 github 问题,您需要使用至少 7.3 tds_version才能成功连接。尝试在CREATE SERVER语句中更改它。

根据这个问题 https://github.com/tds-fdw/tds_fdw/issues/56我认为用户"bpms"没有授予您的表权限。

最新更新