postgresql - python 数据库操作为什么会把record变成string?
怪我咯
怪我咯 2017-04-17 11:46:37
0
1
368

数据库是postgresql,用psycopg2连接,执行以下命令

>>> cur.execute("select (id, company_id) from product_item limit 5")
>>> cur.fetchall()
[('(22165,4)',), ('(25831,1)',), ('(25841,1)',), ('(25852,1)',), ('(22405,4)',)]

我的本意是想把 id和company_id组成一个record,例如(22165, 4).但是结果却组合成了一个字符串'(22165,4)'。 请问怎么能不让python做转换?

怪我咯
怪我咯

走同样的路,发现不同的人生

répondre à tous(1)
PHPzhong

这不是 Python 做的转换。是你的 SQL 语句的问题。不过我还没找到你那个 SQL 语句返回的是什么类型的奇怪东西。

你应试这样写:

select id, company_id from product_item limit 5
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!