#26327: Add JSON_AGG to contrib.postgres
-------------------------------------+-------------------------------------
Reporter: Tomasz Nowak | Owner: (none)
Type: New feature | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: JSON postgres | Triage Stage: Accepted
aggregate |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mads Jensen):
I tried to add this, and also made a test that aggregates a single field;
it's adapted from the StringAgg-function. Would it make more sense to
augment it so it's easier to aggregate several fields, or is this
something that's better done in Python?
Also, JSONB is only available in 9.4+, so maybe some version checking
would be a good idea? It might be slightly misleading that the JSON-
datatype in {{{django.contrib.postgres.fields}}} is actually `jsonb`.
{{{
class JsonAgg(Aggregate):
function = 'JSONB_AGG'
template = '%(function)s(%(expressions)s)'
_output_field = JSONField()
def convert_value(self, value, expression, connection, context):
if not value:
return json.dumps({})
return value
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26327#comment:2>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.f18bbf93674bf5913553948e7b6adfe0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.