#32906: Explain JSONBAgg benefit
--------------------------------------+------------------------------------
     Reporter:  Claude Paroz          |                    Owner:  Abhyudai
         Type:  Cleanup/optimization  |                   Status:  assigned
    Component:  Documentation         |                  Version:  dev
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by Mariusz Felisiak):

 Replying to [comment:5 Abhyudai]:
 > Am I missing something here? The above snippet is just an abstracted
 version of the model inside the package `postgres_tests.models`, used for
 tests.

 They are not the same on the PostgreSQL-level because `ARRAY_AGG()`
 returns array and `JSONB_AGG()` returns JSON array, see my
 [https://code.djangoproject.com/ticket/32906#comment:1 comment]. For
 example:

 {{{
 >>>
 
AggregateTestModel.objects.annotate(jsonbagg=JSONBAgg('json_field')).filter(jsonbagg__0__lang='en').values('jsonbagg')
 <QuerySet [{'jsonbagg': [{'lang': 'en'}]}]>
 >>>
 
AggregateTestModel.objects.annotate(arrayagg=ArrayAgg('json_field')).filter(arrayagg__0__lang='en').values('arrayagg')
   File "/django/django/db/backends/utils.py", line 84, in _execute
     return self.cursor.execute(sql, params)
 psycopg2.errors.SyntaxError: syntax error at or near "["
 LINE 1: ..."postgres_tests_aggregatetestmodel"."json_field" )[1] -> 'la...
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32906#comment:6>
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/065.8666a3227ea9358a86fc62eeacaf0943%40djangoproject.com.

Reply via email to