【发布时间】:2018-01-26 13:46:28
【问题描述】:
我正在尝试将字符串列表插入 Postgres 表中。
字符串是文件夹名称,从 Windows 机器收集,然后重写为 unix 样式的字符串。
这可行,但是当文件夹名称带有“üöä”时,插入不会失败,而是插入一个空字符串。
这是我用来插入值的代码:
def db_insert_paths(paths):
paths.sort()
for path in paths:
print(path)
print(type(path))
cur.execute("INSERT INTO rasp (folder) VALUES (%s)", (path,))
cur.close()
conn.close()
return 0
这里有一些例子: 我还捕获了发送到 Postgres 服务器的流量。
/mnt/hdd/Bilder/2004/2004.08.15. Dorffest
<class 'str'>
INSERT INTO rasp (folder) VALUES ('/mnt/hdd/Bilder/2004/2004.08.15. Dorffest')
此插入有效。数据在表格中。
但是,下一个没有:
/mnt/hdd/Bilder/2004/2004.08.30. Filterschacht räumen und reinigen
<class 'str'>
INSERT INTO rasp (folder) VALUES ('/mnt/hdd/Bilder/2004/2004.08.30. Filterschacht r��umen und reinigen')
条目为空。
我在这里做错了什么?我猜这是某种编码失败。
我在 Windows 8.1 上使用 python3.4 和 Postgresql 9.5。字段类型为“文本”。
【问题讨论】:
标签: python windows postgresql unicode utf-8