Skip to main content

JSONBAgg

This class provides an interface for the PostgreSQL JSONB_AGG aggregate function, which aggregates values into a JSON array. It supports both distinct value filtering and custom ordering of elements within the resulting JSONB field.

Attributes

AttributeTypeDescription
functionstring = JSONB_AGGThe SQL aggregate function name used for database-level JSONB array aggregation.
allow_distinctboolean = trueDetermines whether the DISTINCT keyword can be used within the aggregate function to eliminate duplicate values.
allow_order_byboolean = trueEnables the inclusion of an ORDER BY clause within the aggregate to specify the sequence of elements in the resulting array.
output_field[JSONField](../../../../forms/fields/jsonfield.md?sid=django_forms_fields_jsonfield) = JSONField()Defines the Django model field type used to represent the aggregated result, defaulting to a JSONField.

Constructor

Signature

def JSONBAgg() - > null

Signature

def JSONBAgg(
expression: [Expression](../../../../db/models/expressions/expression.md?sid=django_db_models_expressions_expression),
distinct: bool = False,
filter: [Q](../../../../db/models/query/utils/q.md?sid=django_db_models_query_utils_q) = null,
default: Any = null,
**extra: dict
) - > null

Parameters

NameTypeDescription
expression[Expression](../../../../db/models/expressions/expression.md?sid=django_db_models_expressions_expression)The field or expression to be aggregated into the JSON array
distinctbool = FalseIf True, the aggregate will only include unique values in the resulting JSON array
filter[Q](../../../../db/models/query/utils/q.md?sid=django_db_models_query_utils_q) = nullA conditional expression used to filter the rows that are included in the aggregation
defaultAny = nullThe value to return if the aggregation result is empty
**extradictAdditional keyword arguments to be passed to the parent Aggregate class