能否从SQLAlchemy查询中获取包含字典的聚合数组? 例如:
session.query(
Object.name,
func.array_agg({Location.id: Location.name}).label('locations')
)\
.join(Location)\
.all()
因此,预期结果将是:
[
('Horizontal neutral circuit',
[{143:'A5'},{145:'A8'},{765:'B12'}]),
('Fletcher, Lopez and Edwards',
[{41:'A1'},{76:'B8'},{765:'B12'}]),
]