#35718: Some useful postgres functions for JSON are missing from contrib
----------------------------------+---------------------------------------
Reporter: john-parton | Owner: john-parton
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
----------------------------------+---------------------------------------
Comment (by john-parton):
My use of these functions predate the JSONField being moved out of
contrib, so I'm certainly not saying that's the best way to do it.
My experience with Oracle is effectively zero, and my experience with
SQLite and MySQL is very limited, so it might be challenging for me to
complete that without some assistance from another contributor.
It turns out that `jsonb_build_object` is already implemented as
`django.db.models.functions.JSONObject`. So that's actually done. That
must have been added at some point and I didn't notice.
Another thing I've implemented is removing keys and concatenating objects:
{{{
class JSONConcat(Func):
template = "%(expressions)s"
output_field = JSONField()
arg_joiner = " || "
class JSONDeleteKey(Func):
template = "%(expressions)s"
output_field = JSONField()
arg_joiner = " - "
}}}
Perhaps there is a better way to do this that I'm not seeing?
With respect to "we shouldn't include functions that are trivial to
implement using Func", there are already two such functions in
`django.contrib.postgres.functions`, and arguably the functions
`CumeDist`, `DenseRank`, `FirstValue`, `LastValue`, `PercentRank`, `Rank`,
`RowNumber` all from `django.db.models.functions.window`.
--
Ticket URL: <https://code.djangoproject.com/ticket/35718#comment:5>
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/01070191a1628f01-5f2bc3dd-f7bf-4521-b44a-b8fc1b24ba12-000000%40eu-central-1.amazonses.com.