Jooq order by not in jsonArrayArg

Jooq order by not in jsonArrayArg

需要执行的查询语句为

dslContext.select(
            jsonObject(
                key("id").value(ENTITY.ID),
                key("name").value(ENTITY.NAME),
                key("attributes").value(
                    coalesce(
                        select(
                            jsonArrayAgg(
                                jsonObject(
                                    key("id").value(ATTRIBUTE.ID),
                                    key("name").value(ATTRIBUTE.NAME),
                                    key("indexValue").value(ATTRIBUTE.INDEX_VALUE)
                                )
                            )
                        ).from(ATTRIBUTE)
                            .where(ATTRIBUTE.ENTITY_ID.eq(ENTITY.ID))
                            .orderBy(ATTRIBUTE.INDEX_VALUE.asc()),
                        jsonArray()
                    )
                )
            )
        ).from(ENTITY).fetchInto(EntityDto.class)

上述查询的响应:

[
    {
        "id": 2,
        "name": "Address",
        "attributes": [
            {
                "id": 3,
                "name": "Pincode",
                "indexValue": 4
            },
            {
                "id": 4,
                "name": "Country",
                "indexValue": 3
            },
            {
                "id": 5,
                "name": "City",
                "indexValue": 2
            },
            {
                "id": 6,
                "name": "Address",
                "indexValue": 1
            }
        ]
    }
]

属性未按 indexValue 的升序排序。 如何让属性升序排列?

JSON_ARRAYAGG 上使用 ORDER BY 子句:

jsonArrayAgg(...).orderBy(...)