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?