小编use*_*503的帖子

Python MySQLdb转换器无法正常工作

我正在尝试使用python和MySQLdb运行ETL脚本,但我坚持使用初始提取查询的结果.当我想要Int和Float时,返回的类型都是Long和Decimal.我搜索了几个小时,试图找到答案但没有任何成功.

database = MySQLdb.connect(host='db',user='user',
                       passwd='password', db='db123')

database_cursor = database.cursor()

database_query = ("SELECT id, siteId, campaignId, hour, sum(impressions) AS impressions, "
"sum(clicks) AS clicks, sum(conversions) AS conversions, sum(costs/1000000) AS revenue "
"FROM database.DM_PublisherFact_Hourly WHERE time = '%s' GROUP BY siteId, campaignId;") %(today)

print database_query

database_cursor.execute(database_query)
result = database_cursor.fetchone()

database.close()
Run Code Online (Sandbox Code Playgroud)

返回值是Longs和Decimals的元组.我尝试将转换字典显式传递给connect对象,但没有运气.有帮助吗?

这是转换代码

"""MySQLdb type conversion module

This module handles all the type conversions for MySQL. If the default
type conversions aren't what you need, you can make your own. The
dictionary conversions …
Run Code Online (Sandbox Code Playgroud)

python sql converter mysql-python long-integer

5
推荐指数
1
解决办法
3789
查看次数

标签 统计

converter ×1

long-integer ×1

mysql-python ×1

python ×1

sql ×1