DjangoArrayField - a PostgreSQL-specific field


Syntax

  • from django.contrib.postgres.fields import ArrayField
  • class ArrayField(base_field, size=None, **options)
  • FooModel.objects.filter(array_field_name__contains=[objects, to, check])
  • FooModel.objects.filter(array_field_name__contained_by=[objects, to, check])

Remarks

Note that although the size parameter is passed to PostgreSQL, PostgreSQL will not enforce it.

When using ArrayFields one should keep in mind this word of warning from the Postgresql arrays documentation.

Tip: Arrays are not sets; searching for specific array elements can be a sign of database misdesign. Consider using a separate table with a row for each item that would be an array element. This will be easier to search, and is likely to scale better for a large number of elements.