【发布时间】:2013-06-05 01:20:58
【问题描述】:
这是我用来重现问题的表定义:
create table test_sum_type
(
kind char(1) not null,
n tinyint not null
);
测试数据:
+------+---+
| kind | n |
+------+---+
| A | 1 |
| B | 1 |
| A | 2 |
+------+---+
使用MySQLdb查询:
In [32]: cur.execute("select kind, sum(n) from test_sum_type group by kind")
Out[32]: 2L
In [33]: cur.fetchall()
Out[33]: (('A', Decimal('3')), ('B', Decimal('1')))
In [34]: cur.execute("select kind, n from test_sum_type")
Out[34]: 3L
In [35]: cur.fetchall()
Out[35]: (('A', 1), ('B', 1), ('A', 2))
如您所见,当我使用sum 时,结果列是Decimal。
我查看了MySQLdb的源代码,只有两种字段类型设置为默认转换为Decimal:DECIMAL和NEWDECIMAL。
这可能是什么原因?有什么方法可以检查特定查询中使用的一些临时表的架构?
【问题讨论】:
标签: python mysql mysql-python temp-tables