#32658: Subquery ignores query ordering
-------------------------------------+-------------------------------------
Reporter: Bálint Balina | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: Subquery, | Triage Stage:
annotations, ordering | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Bálint Balina):
* status: closed => new
* resolution: invalid =>
Comment:
Okay, that sounds sane, but the solution you provided does not work:
{{{
children_query = MyModel.objects.filter(
parent=OuterRef('pk'),
).annotate(
child_names=Aggregate('name', function='group_concat'),
).values('child_names').order_by('name')
queryset = MyModel.objects.annotate(
other_names=Subquery(children_query)
).only('id')
print(str(queryset.query))
}}}
{{{
SELECT "app_mymodel"."id", (SELECT ARRAY_AGG(U0."name" ) AS "child_names"
FROM "app_mymodel" U0 WHERE U0."parent_id" = "app_mymodel"."id" GROUP BY
U0."id") AS "other_names" FROM "app_mymodel"
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32658#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/075.41dcbd49231a7b757a87c24574cab4af%40djangoproject.com.