#34107: Django ORM queries do not pick up indexes made on a key in JSONField in
Postgres
-------------------------------------+-------------------------------------
Reporter: Tadek Teleżyński | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: json, jsonfield, | Triage Stage:
postgres, index | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* status: new => closed
* resolution: => invalid
Comment:
I don't think there is anything that Django could do better here. In most
of cases creating indexes via `Meta.indexes` helps to avoid small
differences between defined indexes and used filters.
> To be honest I wasn't able to figure out a query that would pick up the
second index ("CategoryIndex") that's using explicit type casting.
You can try to `Cast(F("data__category"), output_field=TextField())`.
By the way, have you tried to create these indexes via `Meta.indexes`? You
can create them
[https://docs.djangoproject.com/en/4.1/ref/contrib/postgres/operations
/#concurrent-index-operations concurrently] without writing raw SQLs.
--
Ticket URL: <https://code.djangoproject.com/ticket/34107#comment:3>
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/01070183f124e5d2-becf8546-d54d-4cfb-b297-3885e4a6df8b-000000%40eu-central-1.amazonses.com.