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

标签 sql sql-server postgresql freetds foreign-data-wrapper

我使用 freetds 在 postgresql 中设置了外部数据包装器以连接到 SQL Server,并在 postgresql 中安装了 tds_fdw 扩展,但是当从外部表中选择数据时,代码总是会引发此 DB-Library错误:

DB #: 4075 error:
The USE database statement failed because the database collation Persian_100_CI_AI is not recognized by older client drivers. Try upgrading the client operating system or applying a service update to the database client software, or use a different collation. See SQL Server Books Online for more information on changing collations

我深入研究位于 /etc/freetds 中的 net 和配置 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\'' 这样的反斜杠转义字符不起作用,并给出语法错误。

任何帮助将不胜感激..

最佳答案

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

关于sql - 从 SQL Server 检索任何外部表数据时,Postgresql 外部数据包装器引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55552952/

相关文章:

从创建日期开始按年龄范围分组的 SQL 查询

json - 从 Postgres 中的 2 个聚合列构建 JSON

sql - 生成 list 编号

sql-server - SQL Server 中的表 "Inheritance"

sql - 在 SQL Server 中结合使用条件运算符和 INTERSECT

mysql - 从 MySQL 子集中选择多个条件的有效方法

postgresql - 如何将 .csv 文件导入我的 Hasura PostgreSQL 数据库?

c# - 是否可以从 SqlDbType.Xml 类型的输出 SqlParameter 创建 XmlReader?

mysql - 恢复 woocommerce 订单

MySQL:仅当字段值升序时才选择