从ms-sql到postgres-nonascii-characters-error-python的迁移

2024-09-27 23:17:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要创建一个python脚本来将数据从microsoftsqlserver迁移到PostgreSql。非ascii字符出现问题。在microsoftsqlserver中,我有一个名为table1的表,其中有一个nvarchar类型的列,用于存储字符

â

我正在使用pyodbc检索字符。我的连接字符串是

"ms_sql":{
    "DRIVER":"{SQL Server Native Client 11.0}",
    "SERVER":"(localdb)\\v11.0",
    "DATABASE":"sheshant_database",
    "Trusted_Connection":"yes",
    "charset":"SQL_Latin1_General_CP1_CI_AS"

ms sql中的排序规则是sql\u Latin1\u General\u CP1\u ciu AS。 当我用Python检索数据时,它给出

u'\xe2'

然后我通过psycopg2连接到postgres,这是我的连接字符串参数

    "postgres":{
    "host":"127.0.0.1",
    "user":"postgres",
    "password":"regards",
    "database":"cmots",
    "port":"5432"

在PostgreSQL中,客户机和服务器的编码分别是“latin1”和“utf8”。我在psycopg2中使用了这个命令

'insert into table1 values ('+ a +');' // here a is a unicode and a = u'\xe2'

是的。但是存储在PostgreSQL中的数据是

Γ

哪里出了问题?你知道吗


Tags: 数据字符串sqlaspostgres字符databasems

热门问题