#34144: Casting a string inside a JSONField into an integer does not work on
PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Clément Escolano | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: postgresql, | Triage Stage:
jsonfield, cast | 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 much we can do 🤔 as this is a PostgreSQL caveat.
On Django 4.2+ you will be able to use the `KT()` expression (see
[https://docs.djangoproject.com/en/dev/topics/db/queries/#django.db.models.fields.json.KT
docs]), e.g.
{{{#!python
Cast(KT("data__value"), output_field=IntegerField())
}}}
on Django < 4.2 you can use the `KeyTextTransform()` expression, e.g.
{{{#!python
Cast(KeyTextTransform("value", "data"), output_field=IntegerField())
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34144#comment:2>
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/0107018456dc9edc-36fd8d9e-4e2b-40af-b84e-d3f8721c8973-000000%40eu-central-1.amazonses.com.