#31097: StringAgg And ArrayAgg with filtering in subquery generates invalid
string_agg() SQL function call
-------------------------------------+-------------------------------------
     Reporter:  Laurent Tramoy       |                    Owner:  David
                                     |  Wobrock
         Type:  Bug                  |                   Status:  closed
    Component:  contrib.postgres     |                  Version:  3.0
     Severity:  Normal               |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Reupen Shah):

 It does seem that there was a regression in Django 2.2 to me.

 The following query works in Django 2.1.15 and master, but not 2.2.9 and
 3.0.x:

 {{{#!python
 from django.contrib.postgres.aggregates import StringAgg
 from django.db.models import CharField, OuterRef, Q, Subquery

 subquery = Book.objects.annotate(
     _annotated_value=StringAgg(
         'people__first_name', ', ',
         filter=Q(people__first_name='Jane'),
         output_field=CharField(),
     ),
 ).filter(
     pk=OuterRef('pk'),
 ).values(
     '_annotated_value',
 )

 queryset = Book.objects.annotate(names=Subquery(subquery))

 print([book.names for book in queryset])

 }}}

 (I can file a separate bug for that if you want, though.)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31097#comment:15>
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/064.7dff142b20cf4b72f6652414227ce6a3%40djangoproject.com.

Reply via email to