[Django] #35262: Addindex operation generates wrong sql code for Postgresql GinIndex

19 views
Skip to first unread message

Django

unread,
Feb 29, 2024, 11:07:56 AM2/29/24
to django-...@googlegroups.com
#35262: Addindex operation generates wrong sql code for Postgresql GinIndex
-----------------------------------------+------------------------
Reporter: pjuhen | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 5.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Hi,

I have created a Gin Index using the folowing code in models.py

''GinIndex(OpClass(Lower('historique'), name='gin_trgm_ops'),
name="name_gin_trgm_histo_affaire")''

It generates a migration operation :

''migrations.AddIndex(
model_name='affaire',
index=django.contrib.postgres.indexes.GinIndex(django.contrib.postgres.indexes.OpClass(django.db.models.functions.text.Lower('historique'),
name='gin_trgm_ops'), name='name_gin_trgm_histo_affaire'),
),

''

The SQL generated instruction is :


''CREATE INDEX "name_gin_trgm_histo_affaire" ON "affaires_affaire" USING
gin ((LOWER("historique") gin_trgm_ops));''

It is refused by postgresql.

The right code might be :

CREATE INDEX "name_gin_trgm_histo_affaire" ON "affaires_affaire" USING gin
(LOWER("historique") );

that accepted by postgresql.

Thanks,

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

Django

unread,
Feb 29, 2024, 7:29:17 PM2/29/24
to django-...@googlegroups.com
#35262: Addindex operation generates wrong sql code for Postgresql GinIndex
----------------------------------+--------------------------------------
Reporter: pjuhen | Owner: nobody
Type: Bug | Status: new
Component: contrib.postgres | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Tim Graham):

* component: Uncategorized => contrib.postgres


Old description:

> Hi,
>
> I have created a Gin Index using the folowing code in models.py
>
> ''GinIndex(OpClass(Lower('historique'), name='gin_trgm_ops'),
> name="name_gin_trgm_histo_affaire")''
>
> It generates a migration operation :
>
> ''migrations.AddIndex(
> model_name='affaire',
> index=django.contrib.postgres.indexes.GinIndex(django.contrib.postgres.indexes.OpClass(django.db.models.functions.text.Lower('historique'),
> name='gin_trgm_ops'), name='name_gin_trgm_histo_affaire'),
> ),
>
> ''
>
> The SQL generated instruction is :
>

> ''CREATE INDEX "name_gin_trgm_histo_affaire" ON "affaires_affaire" USING
> gin ((LOWER("historique") gin_trgm_ops));''
>
> It is refused by postgresql.
>
> The right code might be :
>
> CREATE INDEX "name_gin_trgm_histo_affaire" ON "affaires_affaire" USING
> gin (LOWER("historique") );
>
> that accepted by postgresql.
>
> Thanks,
>
> Regards,

New description:

I have created a Gin Index using the folowing code in models.py
{{{#!python
GinIndex(OpClass(Lower('historique'), name='gin_trgm_ops'),
name="name_gin_trgm_histo_affaire")
}}}
It generates a migration operation :

{{{#!python
migrations.AddIndex(
model_name='affaire',
index=django.contrib.postgres.indexes.GinIndex(django.contrib.postgres.indexes.OpClass(django.db.models.functions.text.Lower('historique'),
name='gin_trgm_ops'), name='name_gin_trgm_histo_affaire'),
)
}}}

The SQL generated instruction is :

{{{#!sql
CREATE INDEX "name_gin_trgm_histo_affaire" ON "affaires_affaire" USING gin
((LOWER("historique") gin_trgm_ops));
}}}
It is refused by postgresql.

The right code might be :
{{{#!sql
CREATE INDEX "name_gin_trgm_histo_affaire" ON "affaires_affaire" USING gin
(LOWER("historique") );
}}}
that accepted by postgresql.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/35262#comment:1>

Django

unread,
Mar 1, 2024, 12:13:56 AM3/1/24
to django-...@googlegroups.com
#35262: Addindex operation generates wrong sql code for Postgresql GinIndex
----------------------------------+--------------------------------------
Reporter: pjuhen | Owner: nobody
Type: Bug | Status: closed
Component: contrib.postgres | Version: 5.0
Severity: Normal | Resolution: worksforme
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* resolution: => worksforme
* status: new => closed

Comment:

It works for me and is
[https://github.com/django/django/blob/f82c67aa217c8dd4320ef697b04a6da1681aa799/tests/postgres_tests/test_indexes.py#L370-L383
covered] in our test suite.
--
Ticket URL: <https://code.djangoproject.com/ticket/35262#comment:2>

Django

unread,
Mar 16, 2024, 6:30:33 AM3/16/24
to django-...@googlegroups.com
#35262: Addindex operation generates wrong sql code for Postgresql GinIndex
----------------------------------+--------------------------------------
Reporter: Pierre Juhen | Owner: nobody
Type: Bug | Status: closed
Component: contrib.postgres | Version: 5.0
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Tim Graham):

* resolution: worksforme => duplicate

Comment:

Duplicate of #33021. `django.contrib.postgres` must be in `INSTALLED_APPS`
when using `OpClass()`. See
[https://docs.djangoproject.com/en/stable/ref/contrib/postgres/indexes
/#opclass-expressions docs] and related ticket #32770.
--
Ticket URL: <https://code.djangoproject.com/ticket/35262#comment:3>
Reply all
Reply to author
Forward
0 new messages