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
| Attribute | Type | Description |
|---|---|---|
| function | string = JSONB_AGG | The SQL aggregate function name used for database-level JSONB array aggregation. |
| allow_distinct | boolean = true | Determines whether the DISTINCT keyword can be used within the aggregate function to eliminate duplicate values. |
| allow_order_by | boolean = true | Enables 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
| Name | Type | Description |
|---|---|---|
| expression | [Expression](../../../../db/models/expressions/expression.md?sid=django_db_models_expressions_expression) | The field or expression to be aggregated into the JSON array |
| distinct | bool = False | If 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) = null | A conditional expression used to filter the rows that are included in the aggregation |
| default | Any = null | The value to return if the aggregation result is empty |
| **extra | dict | Additional keyword arguments to be passed to the parent Aggregate class |