From 3aa545281e0c0f9fac93753e3769df9e0334dbaa Mon Sep 17 00:00:00 2001 From: Hannes Ljungberg Date: Sat, 6 Feb 2021 20:45:54 +0100 Subject: Fixed #30916 -- Added support for functional unique constraints. Thanks Ian Foote and Mariusz Felisiak for reviews. --- docs/ref/contrib/postgres/indexes.txt | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'docs/ref/contrib/postgres') diff --git a/docs/ref/contrib/postgres/indexes.txt b/docs/ref/contrib/postgres/indexes.txt index b6a4aba808..9a9b7fc73b 100644 --- a/docs/ref/contrib/postgres/indexes.txt +++ b/docs/ref/contrib/postgres/indexes.txt @@ -183,10 +183,10 @@ available from the ``django.contrib.postgres.indexes`` module. .. class:: OpClass(expression, name) An ``OpClass()`` expression represents the ``expression`` with a custom - `operator class`_ that can be used to define functional indexes. To use it, - you need to add ``'django.contrib.postgres'`` in your - :setting:`INSTALLED_APPS`. Set the ``name`` parameter to the name of the - `operator class`_. + `operator class`_ that can be used to define functional indexes or unique + constraints. To use it, you need to add ``'django.contrib.postgres'`` in + your :setting:`INSTALLED_APPS`. Set the ``name`` parameter to the name of + the `operator class`_. For example:: @@ -197,4 +197,18 @@ available from the ``django.contrib.postgres.indexes`` module. creates an index on ``Lower('username')`` using ``varchar_pattern_ops``. + Another example:: + + UniqueConstraint( + OpClass(Upper('description'), name='text_pattern_ops'), + name='upper_description_unique', + ) + + creates a unique constraint on ``Upper('description')`` using + ``text_pattern_ops``. + + .. versionchanged:: 4.0 + + Support for functional unique constraints was added. + .. _operator class: https://www.postgresql.org/docs/current/indexes-opclass.html -- cgit v1.3