#35718: json_array missing from django.db.models.functions
----------------------------------+---------------------------------------
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
----------------------------------+---------------------------------------
Changes (by john-parton):
* summary: Some useful postgres functions for JSON are missing from
contrib => json_array missing from django.db.models.functions
Old description:
> There's a large number of postgres-specific functions for manipulating
> json: https://www.postgresql.org/docs/current/functions-json.html
>
> In my projects for work, I have created several:
>
> * ~~jsonb_build_object~~ -- Actually already implemented as
> `django.db.models.functions.JSONObject`
> * jsonb_build_array
> * jsonb_array_elements
> * ~~jsonb_extract_path~~ Functionally equivalent to the `#>` operator
> * ~~jsonb_extract_path_text~~ Functionally equivalent to the `#>>`
> operator
> * jsonb_array_length
>
> There also a few operators that I implemented as django functions
>
> * jsonb || jsonb -> jsonb - Concatenates two jsonb values
> * jsonb - text -> jsonb - Deletes a key (and its value) from a JSON
> object
>
> It would be nice if these were included in `contrib.postgres.functions`,
> ideally in a submodule like `contrib.postgres.function.json` to allow
> room to expand.
>
> I know postgres's json support is a bit of test-bed for more fleshed out
> json support in general, but I would recommend just adding things as
> postgres-specific to limit the scope of the changes.
>
> I can open a basic pull request.
New description:
This ticket was originally opened with the intent for me to provide
implementations for a bunch of postgres functions, but it became clear
from discussion that the most important bit was to implement a non-
postgres-specific JSONArray function.
Original post:
There's a large number of postgres-specific functions for manipulating
json: https://www.postgresql.org/docs/current/functions-json.html
In my projects for work, I have created several:
* ~~jsonb_build_object~~ -- Actually already implemented as
`django.db.models.functions.JSONObject`
* jsonb_build_array
* jsonb_array_elements
* ~~jsonb_extract_path~~ Functionally equivalent to the `#>` operator
* ~~jsonb_extract_path_text~~ Functionally equivalent to the `#>>`
operator
* jsonb_array_length
There also a few operators that I implemented as django functions
* jsonb || jsonb -> jsonb - Concatenates two jsonb values
* jsonb - text -> jsonb - Deletes a key (and its value) from a JSON object
It would be nice if these were included in `contrib.postgres.functions`,
ideally in a submodule like `contrib.postgres.function.json` to allow room
to expand.
I know postgres's json support is a bit of test-bed for more fleshed out
json support in general, but I would recommend just adding things as
postgres-specific to limit the scope of the changes.
I can open a basic pull request.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/35718#comment:10>
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/01070191beb39a58-724687d6-5622-47af-9d84-0e4985e410ad-000000%40eu-central-1.amazonses.com.