Skip to content

Commit

Permalink
Refs #26327 -- Renamed JsonAgg to JSONBAgg.
Browse files Browse the repository at this point in the history
Thanks to Christian von Roques for the report.
  • Loading branch information
atombrella authored and timgraham committed Nov 28, 2016
1 parent 6252fd6 commit aa2cb4c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions django/contrib/postgres/aggregates/general.py
Expand Up @@ -2,7 +2,7 @@
from django.db.models.aggregates import Aggregate

__all__ = [
'ArrayAgg', 'BitAnd', 'BitOr', 'BoolAnd', 'BoolOr', 'JsonAgg', 'StringAgg',
'ArrayAgg', 'BitAnd', 'BitOr', 'BoolAnd', 'BoolOr', 'JSONBAgg', 'StringAgg',
]


Expand Down Expand Up @@ -31,7 +31,7 @@ class BoolOr(Aggregate):
function = 'BOOL_OR'


class JsonAgg(Aggregate):
class JSONBAgg(Aggregate):
function = 'JSONB_AGG'
_output_field = JSONField()

Expand Down
4 changes: 4 additions & 0 deletions django/db/backends/postgresql/features.py
Expand Up @@ -40,3 +40,7 @@ def has_select_for_update_skip_locked(self):
@cached_property
def has_jsonb_datatype(self):
return self.connection.pg_version >= 90400

@cached_property
def has_jsonb_agg(self):
return self.connection.pg_version >= 90500
8 changes: 4 additions & 4 deletions docs/ref/contrib/postgres/aggregates.txt
Expand Up @@ -58,14 +58,14 @@ General-purpose aggregation functions
Returns ``True`` if at least one input value is true, ``None`` if all
values are null or if there are no values, otherwise ``False``.

``JsonAgg``
-----------
``JSONBAgg``
------------

.. class:: JsonAgg(expressions, **extra)
.. class:: JSONBAgg(expressions, **extra)

.. versionadded:: 1.11

Returns the input values as a ``JSON`` array.
Returns the input values as a ``JSON`` array. Requires PostgreSQL ≥ 9.5.

``StringAgg``
-------------
Expand Down
2 changes: 1 addition & 1 deletion docs/releases/1.11.txt
Expand Up @@ -183,7 +183,7 @@ Minor features
operation allow using PostgreSQL's ``citext`` extension for case-insensitive
lookups.

* The new :class:`~django.contrib.postgres.aggregates.JsonAgg` allows
* The new :class:`~django.contrib.postgres.aggregates.JSONBAgg` allows
aggregating values as a JSON array.

:mod:`django.contrib.redirects`
Expand Down
10 changes: 5 additions & 5 deletions tests/postgres_tests/test_aggregates.py
Expand Up @@ -9,7 +9,7 @@

try:
from django.contrib.postgres.aggregates import (
ArrayAgg, BitAnd, BitOr, BoolAnd, BoolOr, Corr, CovarPop, JsonAgg,
ArrayAgg, BitAnd, BitOr, BoolAnd, BoolOr, Corr, CovarPop, JSONBAgg,
RegrAvgX, RegrAvgY, RegrCount, RegrIntercept, RegrR2, RegrSlope,
RegrSXX, RegrSXY, RegrSYY, StatAggregate, StringAgg,
)
Expand Down Expand Up @@ -117,14 +117,14 @@ def test_string_agg_empty_result(self):
values = AggregateTestModel.objects.aggregate(stringagg=StringAgg('char_field', delimiter=';'))
self.assertEqual(values, {'stringagg': ''})

@skipUnlessDBFeature('has_jsonb_datatype')
@skipUnlessDBFeature('has_jsonb_agg')
def test_json_agg(self):
values = AggregateTestModel.objects.aggregate(jsonagg=JsonAgg('char_field'))
values = AggregateTestModel.objects.aggregate(jsonagg=JSONBAgg('char_field'))
self.assertEqual(values, {'jsonagg': ['Foo1', 'Foo2', 'Foo3', 'Foo4']})

@skipUnlessDBFeature('has_jsonb_datatype')
@skipUnlessDBFeature('has_jsonb_agg')
def test_json_agg_empty(self):
values = AggregateTestModel.objects.none().aggregate(jsonagg=JsonAgg('integer_field'))
values = AggregateTestModel.objects.none().aggregate(jsonagg=JSONBAgg('integer_field'))
self.assertEqual(values, json.loads('{"jsonagg": []}'))


Expand Down

0 comments on commit aa2cb4c

Please sign in to comment.