Skip to content

When using the json_group_array method, the orderBy clause is not worked. #2968

Answered by simolus3
qmr777 asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for starting this discussion! I think the problem is that the order by clause needs to be part of the aggregate function invocation, the order is technically still undefined even when using a statement-wide ordering.

Fixing this right now is not trivial since drift's query builder is not currently exporting a way to write aggregate functions (fixed in a68ec2a). So in the next drift release, you could simply do childInfo.id.jsonGroupArray(orderBy: OrderBy([OrderingTerm.asc(childInfo.left)])). Until then, I think the most viable option is to use a CustomExpression with the manual SQL invocation (e.g. json_group_array(childInfo.id ORDER BY childInfo.left ASC).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@qmr777
Comment options

Answer selected by qmr777
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants