#32932: Unique indexes
-------------------------------------+-------------------------------------
               Reporter:  David      |          Owner:  nobody
  Sanders                            |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  3.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Django already supports both unique constraints and indexes from the
 models Meta <3

 A worthwhile addition would be to support _unique indexes_, if the
 database makes this distinction.

 In Postgres a unique index is a distinct feature from unique constraints;
 unique indexes are the mechanism that enforces the unique constraints
 declared for the table: https://www.postgresql.org/docs/current/indexes-
 unique.html.

 One important difference between the 2 is the fact that indexes may
 support expressions whereas constraints do not (at least in PG).

 An example may be to enforce a unique attribute in a jsonb field:


 {{{
 CREATE UNIQUE INDEX unique_attr ON some_table (
 (some_json_field->>'some_attr') )
 }}}

 This could perhaps be a new option on the `Index` class:

 {{{
 class SomeTable(models.Model):
     some_json_field = models.JSONField()

     class Meta:
         indexes = (
             models.Index(models.RawSQL("some_json_field->>'some_attr'",
 params=[]), name="unique_attr", unique=True),
         )
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32932>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.7f2051631712b378be37a1759399dce3%40djangoproject.com.

Reply via email to