JSONB sqlalchemy Aggregate Function

后端 未结 2 1755
夕颜
夕颜 2021-01-14 22:38

With SQLAlchemy I want to reproduce the available aggregate function jsonb_object_agg from a subquery sq_objects:

from sqlalchemy import select,         


        
2条回答
  •  旧巷少年郎
    2021-01-14 22:58

    Not the most elegant implementation, but since I now the labels of the subquery columns; a raw text input solves the issue:

    func.jsonb_object_agg(
        text("sq_objects.keys"),
        text("sq_objects.values")
    ).over(
        partition_by=sq_objects.c.object_id).label("attributes"),
    

提交回复
热议问题