JSONB sqlalchemy Aggregate Function

后端 未结 2 1753
夕颜
夕颜 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 23:05

    The problem is that the attributes keys and values are methods of the immutable column collection sq_objects.c. Another solution to the problem is to use item access notation for getting the actual columns:

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

提交回复
热议问题