mysql 游标 前缀_python – 强制mysqldb dict游标返回带有表名的所有列名前缀

SELECT * FROM a, b WHERE ...

Mysql允许在查询结果中使用重复的列名.因此,在终端中,没有列名称使用上述查询作为前缀.

但是,我在使用DictCursor的python中使用mysqldb.结果是列表名称为键的字典列表.有时,dict游标会自动在列名前加上表名.据我所知,它是针对两个不明确的列名称中的第二个,但仅当第二个值是唯一的时才这样做.无论如何,我想强制光标使用表名为所有键添加前缀.

从mysqldb docs上的fetch.row()函数…

The second parameter (how) tells it how the row should be represented.

By default, it is zero which means, return as a tuple. how=1 means,

return it as a dictionary, where the keys are the column names, or

table.column if there are two columns with the same name (say, from a

join). how=2 means the same as how=1 except that the keys are always

table.column; this is for compatibility with the old Mysqldb module.

所以,它似乎可行,但我没有直接使用fetch.row()函数…所以问题是,如何在获取行时使mysqldb dict游标始终使用how = 2?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值