Python Sqlalchemy数组长度函数

Python Sqlalchemy数组长度函数,python,postgresql,sqlalchemy,flask-sqlalchemy,Python,Postgresql,Sqlalchemy,Flask Sqlalchemy,SQLALCHEMY是否有用于查询数组长度的函数 即: 使用max和array_length修复了它 data = ssn.query(models.MedicationLog.dose_date, func.sum(func.array_length( models.MedicationLog.dose_taken_times, ARRAY_DEPTH

SQLALCHEMY是否有用于查询数组长度的函数

即:


使用max和array_length修复了它

data = ssn.query(models.MedicationLog.dose_date,
                         func.sum(func.array_length(
                             models.MedicationLog.dose_taken_times, ARRAY_DEPTH
                         )).label('dose_taken_times')).order_by(models.MedicationLog.dose_date).\
        group_by(models.MedicationLog.dose_date).all()

你是说长度还是长度?下面是一个关于如何使用此.Length的示例。因为计数不会给出数组的长度。但是让我检查一下总数。谢谢@AKS接受两个参数
array\u长度(array,dimension)
@AKS谢谢。它是有效的,我唯一需要做的改变是使用最大聚集函数,因为我没有在小组中的剂量。请在答案中添加您所做的更改并接受它。
data = ssn.query(models.MedicationLog.dose_date,
                         func.sum(func.array_length(
                             models.MedicationLog.dose_taken_times, ARRAY_DEPTH
                         )).label('dose_taken_times')).order_by(models.MedicationLog.dose_date).\
        group_by(models.MedicationLog.dose_date).all()