【发布时间】:2016-11-25 10:09:18
【问题描述】:
我使用以下代码从 PostgreSQL 查询中得到结果:
cur = con.cursor()
cur.execute("""SELECT to_char(tt.service_date,'yyyy-mm-01') AS txn_month,
SUM (tt.customer) AS customer,SUM (tt.tour) AS tour,
SUM (tt.distancetraveled) AS distancetraveled
FROM
tbl_travel as tt
GROUP BY
txn_month""")
rows = cur.fetchall()
我的查询结果是这样的:
[('2016-01-01', Decimal('11.0909090909090909'), Decimal('3.7272727272727273'), 58.5354545454545),
('2016-02-01', Decimal('11.6666666666666667'), Decimal('4.0000000000000000'), 74.8766666666667)]
我需要删除值前面的“十进制”字符串并得到如下结果:
[('2016-01-01', '11.0909090909090909', '3.7272727272727273','58.5354545454545'),
('2016-02-01', '11.6666666666666667', '4.0000000000000000','74.8766666666667')]
【问题讨论】:
-
能否请您展示执行该查询的 Python 代码?
-
在这种情况下
Decimal来自哪里? “十进制”字符串 - 它看起来不像字符串 -
将 double 类型转换为 bigInt (Postgresql) 的示例:dba.stackexchange.com/questions/3429/…
-
postgresql 舍入函数的完整列表:postgresql.org/docs/current/static/functions-math.html
标签: python python-3.x