search

Home  >  Q&A  >  body text

postgresql - python 数据库操作为什么会把record变成string?

数据库是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做转换?

怪我咯怪我咯2767 days ago401

reply all(1)I'll reply

  • PHPz

    PHPz2017-04-17 11:48:37

    This is not a conversion done by Python. It's a problem with your SQL statement. But I haven’t found out what type of strange thing your SQL statement returns.

    You should write like this for the exam:

    select id, company_id from product_item limit 5
    

    reply
    0
  • Cancelreply