Opened 7 years ago

Closed 6 years ago

Last modified 4 years ago

#28077 closed New feature (fixed)

Allow specifying custom operator classes for PostgreSQL indexes

Reported by: IzyJeepee Owned by: Ian Foote
Component: Database layer (models, ORM) Version: 1.11
Severity: Normal Keywords: postgres, gin, operator, class
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



I want use the GinIndex method to create a gin index with the django's migration. But while the migration, I have this errror :

django.db.utils.ProgrammingError : data type character varying has no default operator class for access method "gin"
HINT : You must specify an operator class ofr the index or define a default operator class for the data type.

This error may be resolved by enabling the btree_gin extension.

It is possible to pass the operator class during the index's creation ? For example :

class Meta:
    indexes = [
        GinIndex(fields=['my_field'], name='my_index_gin', operator_class='my_operator')


Change History (9)

comment:2 by Mads Jensen, 7 years ago

#27437 looks like it's overlapping a little bit.

comment:3 by Tim Graham, 7 years ago

Summary: GinIndex() and operator classAllow specifying an operator class for GinIndex()
Triage Stage: UnreviewedAccepted

I don't have much expertise here about the use cases and how this might interact with #27437. Tentatively accepting for further investigation.

comment:5 by vinay karanam, 6 years ago

I've a use case where I am always doing __contains query on JSONField. So, I would prefer GIN index to be created using jsonb_path_ops operator class rather than the default jsonb_ops.

comment:6 by Tim Graham, 6 years ago

Component: contrib.postgresDatabase layer (models, ORM)
Has patch: set
Owner: set to nobody
Summary: Allow specifying an operator class for GinIndex()Allow specifying custom operator classes for PostgreSQL indexes

#28783 was a duplicate and provides a PR.

comment:7 by Ian Foote, 6 years ago

Owner: changed from nobody to Ian Foote
Status: newassigned
Last edited 6 years ago by Tim Graham (previous) (diff)

comment:8 by Ian Foote, 6 years ago

I've noticed that in the postgis schema editor, we have custom index creation code for single-field indexes for geodetic fields. For example, we set the GIST_GEOMETRY_OPS_ND operator class for fields with dimension higher than two.

It would probably be good to refactor to allow this custom code to integrate with the operator class support I've added, but I'm not familiar enough with postgis to be confident making a change without guidance.

comment:9 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 38cada7:

Fixed #28077 -- Added support for PostgreSQL opclasses in Index.

Thanks Vinay Karanam for the initial patch.

comment:10 by GitHub <noreply@…>, 4 years ago

In 82da72b:

Refs #28077 -- Added opclasses to Index.repr().

This also removes unnecessary commas between attributes.

Note: See TracTickets for help on using tickets.
Back to Top