#32770: GinIndex with OpClass and Cast results in Postgres syntax error in
migration
--------------------------------------+------------------------
               Reporter:  syastrov    |          Owner:  nobody
                   Type:  Bug         |         Status:  new
              Component:  Migrations  |        Version:  3.2
               Severity:  Normal      |       Keywords:
           Triage Stage:  Unreviewed  |      Has patch:  0
    Needs documentation:  0           |    Needs tests:  0
Patch needs improvement:  0           |  Easy pickings:  1
                  UI/UX:  0           |
--------------------------------------+------------------------
 Given the following model + index:

 {{{
 from django.db import models
 from django.contrib.postgres.indexes import GinIndex, OpClass
 from django.db.models.functions import Cast

 class MyModel(models.Model):
     class Meta:
         indexes = [
             GinIndex(OpClass(Cast("id", output_field=models.TextField()),
 name='gin_trgm_ops'), name='foobar')
         ]

 }}}

 After running makemigrations and running the migration, it produces the
 SQL:

 {{{
 CREATE INDEX "foobar" ON "myapp_mymodel" USING gin ((CAST("id" AS text)
 gin_trgm_ops));
 }}}

 Which is a syntax error on Postgres (version 12). The reason is the extra
 parentheses around CAST.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32770>
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/051.d8273f337be12810ae3fd3ab9b288a11%40djangoproject.com.

Reply via email to