没有与给定名称和参数类型匹配的函数。在postgres中使用python

没有与给定名称和参数类型匹配的函数。在postgres中使用python,python,sql,postgresql,count,aggregate-functions,Python,Sql,Postgresql,Count,Aggregate Functions,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(ta

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数据库进行查询 但是,我开始犯错误了


请看一看

您不能像预期的那样对字符串值求和。如果要计算表中每个订单号的不同国家/地区的数量,请使用
count(distinct)


你想干什么
country
是一个字符串,不能求和。
SELECT ordernumber, COUNT(DISTINCT country) cnt_country 
FROM soubhagyasalesdata 
GROUP BY ordernumber