With SQLAlchemy I want to reproduce the available aggregate function jsonb_object_agg from a subquery sq_objects:
sq_objects
from sqlalchemy import select,
Not the most elegant implementation, but since I now the labels of the subquery columns; a raw text input solves the issue:
text
func.jsonb_object_agg( text("sq_objects.keys"), text("sq_objects.values") ).over( partition_by=sq_objects.c.object_id).label("attributes"),