Skip to main content

ArraySubquery

This class represents a subquery that is wrapped in an ARRAY() constructor, allowing a queryset to be used as an array expression. It automatically determines its output type by wrapping the inner query's output field in an ArrayField.

Attributes

AttributeTypeDescription
templatestring = ARRAY(%(subquery)s)The SQL template used to wrap the subquery in an ARRAY constructor for database execution.
output_field[ArrayField](../fields/array/arrayfield.md?sid=django_contrib_postgres_fields_array_arrayfield)The field type of the subquery result, automatically wrapped in an ArrayField to represent a collection of values.

Constructor

Signature

def ArraySubquery(
queryset: [QuerySet](../../../db/models/query/queryset.md?sid=django_db_models_query_queryset),
**kwargs: dict
) - > null

Parameters

NameTypeDescription
queryset[QuerySet](../../../db/models/query/queryset.md?sid=django_db_models_query_queryset)The queryset to be used in the array subquery.
**kwargsdictAdditional keyword arguments passed to the parent Subquery class.

Signature

def ArraySubquery(
queryset: [QuerySet](../../../db/models/query/queryset.md?sid=django_db_models_query_queryset),
**kwargs: dict
)

Parameters

NameTypeDescription
queryset[QuerySet](../../../db/models/query/queryset.md?sid=django_db_models_query_queryset)The Django QuerySet to be evaluated as a subquery.
**kwargsdictAdditional keyword arguments passed to the parent Subquery class, such as output_field or alias.

Methods


output_field()

@classmethod
def output_field() - > [ArrayField](../fields/array/arrayfield.md?sid=django_contrib_postgres_fields_array_arrayfield)

Determines the resulting data type of the subquery by wrapping the inner query's output field in an ArrayField.

Returns

TypeDescription
[ArrayField](../fields/array/arrayfield.md?sid=django_contrib_postgres_fields_array_arrayfield)An ArrayField instance that represents a list of the inner subquery's return type.