summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorHannes Ljungberg <hannes.ljungberg@gmail.com>2021-11-03 22:21:50 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-12-24 11:39:00 +0100
commit0e656c02fe945389246f0c08f51c6db4a0849bd2 (patch)
treee61981acccc088365ca767c8a2b61883313f0231 /docs
parenta0d43a7a6e1c30c08f853ba64e17e148fb6921e6 (diff)
Fixed #33342 -- Added support for using OpClass() in exclusion constraints.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/postgres/constraints.txt18
-rw-r--r--docs/ref/contrib/postgres/indexes.txt25
-rw-r--r--docs/releases/4.1.txt4
3 files changed, 41 insertions, 6 deletions
diff --git a/docs/ref/contrib/postgres/constraints.txt b/docs/ref/contrib/postgres/constraints.txt
index be06b907ff..fe7d53bb79 100644
--- a/docs/ref/contrib/postgres/constraints.txt
+++ b/docs/ref/contrib/postgres/constraints.txt
@@ -53,6 +53,10 @@ operators with strings. For example::
Only commutative operators can be used in exclusion constraints.
+.. versionchanged:: 4.1
+
+ Support for the ``OpClass()`` expression was added.
+
``index_type``
--------------
@@ -143,6 +147,20 @@ For example::
creates an exclusion constraint on ``circle`` using ``circle_ops``.
+Alternatively, you can use
+:class:`OpClass() <django.contrib.postgres.indexes.OpClass>` in
+:attr:`~ExclusionConstraint.expressions`::
+
+ ExclusionConstraint(
+ name='exclude_overlapping_opclasses',
+ expressions=[(OpClass('circle', 'circle_ops'), RangeOperators.OVERLAPS)],
+ )
+
+.. versionchanged:: 4.1
+
+ Support for specifying operator classes with the ``OpClass()`` expression
+ was added.
+
Examples
--------
diff --git a/docs/ref/contrib/postgres/indexes.txt b/docs/ref/contrib/postgres/indexes.txt
index 35de2bf31a..ba4706da3c 100644
--- a/docs/ref/contrib/postgres/indexes.txt
+++ b/docs/ref/contrib/postgres/indexes.txt
@@ -150,10 +150,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 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`_.
+ `operator class`_ that can be used to define functional indexes, functional
+ unique constraints, or exclusion 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::
@@ -163,8 +163,7 @@ 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'),
@@ -173,9 +172,23 @@ available from the ``django.contrib.postgres.indexes`` module.
creates a unique constraint on ``Upper('description')`` using
``text_pattern_ops``.
+ ::
+
+ ExclusionConstraint(
+ name='exclude_overlapping_ops',
+ expressions=[
+ (OpClass('circle', name='circle_ops'), RangeOperators.OVERLAPS),
+ ],
+ )
+
+ creates an exclusion constraint on ``circle`` using ``circle_ops``.
.. versionchanged:: 4.0
Support for functional unique constraints was added.
+ .. versionchanged:: 4.1
+
+ Support for exclusion constraints was added.
+
.. _operator class: https://www.postgresql.org/docs/current/indexes-opclass.html
diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt
index f2a168db40..d9a05f3bda 100644
--- a/docs/releases/4.1.txt
+++ b/docs/releases/4.1.txt
@@ -108,6 +108,10 @@ Minor features
<django.contrib.postgres.fields.DecimalRangeField.default_bounds>` allows
specifying bounds for list and tuple inputs.
+* :class:`~django.contrib.postgres.constraints.ExclusionConstraint` now allows
+ specifying operator classes with the
+ :class:`OpClass() <django.contrib.postgres.indexes.OpClass>` expression.
+
:mod:`django.contrib.redirects`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~