【问题标题】:No function matches the given name and argument types. in postgres with python没有函数匹配给定的名称和参数类型。在带有 python 的 postgres 中
【发布时间】:2021-02-13 00:42:33
【问题描述】:

python 代码:

    if aggregate_name and aggregate_value and aggregate_type:
        query = "SELECT SUM(country) FROM soubhagyasalesdata GROUP BY ordernumber"
        print(query)
    else:
        query = "SELECT * FROM {}".format(table_name)

错误:

    UndefinedFunction at /api/datasets/reports/
    function sum(text) does not exist
    LINE 1: SELECT SUM(country) FROM soubhagyasalesdata GROUP BY ordernu...
                ^
    HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

我在这里尝试使用 python 从我的 postgres 数据库中查询 但是,我正在处理错误。

请看一下

【问题讨论】:

  • 你想做什么? country 是字符串,不能求和。

标签: python sql postgresql count aggregate-functions


【解决方案1】:

您不能像预期的那样对字符串值求和。如果您想计算每个订单号在表中存在多少不同的国家,请使用count(distinct)

SELECT ordernumber, COUNT(DISTINCT country) cnt_country 
FROM soubhagyasalesdata 
GROUP BY ordernumber

【讨论】:

    猜你喜欢
    • 2013-08-20
    • 2018-02-25
    • 2014-09-05
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-20
    相关资源
    最近更新 更多