diff options
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/contrib/postgres/fields.txt | 10 | ||||
| -rw-r--r-- | docs/ref/contrib/postgres/operations.txt | 50 |
2 files changed, 60 insertions, 0 deletions
diff --git a/docs/ref/contrib/postgres/fields.txt b/docs/ref/contrib/postgres/fields.txt index cd3908cf2e..df9ebc48d6 100644 --- a/docs/ref/contrib/postgres/fields.txt +++ b/docs/ref/contrib/postgres/fields.txt @@ -285,6 +285,16 @@ transform do not change. For example:: .. _citext: https://www.postgresql.org/docs/current/citext.html .. _the performance considerations: https://www.postgresql.org/docs/current/citext.html#id-1.11.7.17.7 +.. admonition:: Case-insensitive collations + + On PostgreSQL 12+, it's preferable to use non-deterministic collations + instead of the ``citext`` extension. You can create them using the + :class:`~django.contrib.postgres.operations.CreateCollation` migration + operation. For more details, see :ref:`manage-postgresql-collations` and + the PostgreSQL documentation about `non-deterministic collations`_. + + .. _non-deterministic collations: https://www.postgresql.org/docs/current/collation.html#COLLATION-NONDETERMINISTIC + ``HStoreField`` =============== diff --git a/docs/ref/contrib/postgres/operations.txt b/docs/ref/contrib/postgres/operations.txt index 5e4c7af6a5..ff37728d27 100644 --- a/docs/ref/contrib/postgres/operations.txt +++ b/docs/ref/contrib/postgres/operations.txt @@ -115,6 +115,56 @@ them. In that case, connect to your Django database and run the query Installs the ``unaccent`` extension. +.. _manage-postgresql-collations: + +Managing collations using migrations +==================================== + +.. versionadded:: 3.2 + +If you need to filter or order a column using a particular collation that your +operating system provides but PostgreSQL does not, you can manage collations in +your database using a migration file. These collations can then be used with +the ``db_collation`` parameter on :class:`~django.db.models.CharField`, +:class:`~django.db.models.TextField`, and their subclasses. + +For example, to create a collation for German phone book ordering:: + + from django.contrib.postgres.operations import CreateCollation + + class Migration(migrations.Migration): + ... + + operations = [ + CreateCollation( + 'german_phonebook', + provider='icu', + locale='und-u-ks-level2', + ), + ... + ] + +.. class:: CreateCollation(name, locale, *, provider='libc', deterministic=True) + + Creates a collation with the given ``name``, ``locale`` and ``provider``. + + Set the ``deterministic`` parameter to ``False`` to create a + non-deterministic collation, such as for case-insensitive filtering. + +.. class:: RemoveCollation(name, locale, *, provider='libc', deterministic=True) + + Removes the collations named ``name``. + + When reversed this is creating a collation with the provided ``locale``, + ``provider``, and ``deterministic`` arguments. Therefore, ``locale`` is + required to make this operation reversible. + +.. admonition:: Restrictions + + PostgreSQL 9.6 only supports the ``'libc'`` provider. + + Non-deterministic collations are supported only on PostgreSQL 12+. + Concurrent index operations =========================== |
