Opened 18 months ago
Last modified 2 months ago
#35462 assigned New feature
Add support JSONArrayAgg
| Reported by: | Robert Silén | Owned by: | Lufafa Joshua |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 5.0 |
| Severity: | Normal | Keywords: | aggregation, ArrayAgg |
| Cc: | Hisham Mahmood, Sage Abdullah | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I suggest to add ArrayAgg and related (aggregation) functions for MariaDB to Django. It has been noted in MariaDB Foundation ticket: https://jira.mariadb.org/browse/MDBF-690
E.g. ArrayAgg is mentioned on PostgreSQL specific aggregation functions:
https://docs.djangoproject.com/en/dev/ref/contrib/postgres/aggregates/#arrayagg
The equivalent in MariaDB is presumably this:
https://mariadb.com/kb/en/json_arrayagg/
More equivalent MariaDB aggregate functions are listed at the following address.
https://mariadb.com/kb/en/aggregate-functions/
Some have same name 1:1. I'm guessing e.g. StringAgg could be done with GROUP_CONCAT.
Feel free to ask more here, or in the MariaDB Foundation ticket.
Change History (18)
comment:1 by , 18 months ago
| Description: | modified (diff) |
|---|
comment:2 by , 18 months ago
| Description: | modified (diff) |
|---|
comment:3 by , 18 months ago
| Component: | Uncategorized → Database layer (models, ORM) |
|---|---|
| Summary: | ArrayAgg and others for MariaDB → Add support JSONArrayAgg |
| Triage Stage: | Unreviewed → Accepted |
comment:4 by , 17 months ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 17 months ago
| Cc: | added |
|---|
comment:7 by , 16 months ago
| Needs documentation: | set |
|---|
comment:8 by , 16 months ago
| Needs tests: | set |
|---|---|
| Patch needs improvement: | set |
comment:9 by , 14 months ago
| Needs documentation: | unset |
|---|---|
| Needs tests: | unset |
| Patch needs improvement: | unset |
comment:10 by , 13 months ago
| Patch needs improvement: | set |
|---|
comment:11 by , 12 months ago
| Patch needs improvement: | unset |
|---|
comment:12 by , 12 months ago
| Cc: | added |
|---|
comment:13 by , 11 months ago
| Patch needs improvement: | set |
|---|
comment:15 by , 7 months ago
| Patch needs improvement: | unset |
|---|
comment:16 by , 7 months ago
| Needs documentation: | set |
|---|
Hi Joshua,
I had a look at the solution using sqlite and added some notes to your pull request. My notes are about trying to utilise the feature using the documentation, rather than reviewing the code or the tests.
Hope this helps.
Kevin
comment:17 by , 7 months ago
| Patch needs improvement: | set |
|---|
comment:18 by , 2 months ago
| Needs documentation: | unset |
|---|---|
| Patch needs improvement: | unset |
The
contrib.postgres.ArrayAggexpression you pointed at uses Postgres arrays and MariaDB doesn't have native array support so they are not equivalent.JSON_ARRAYAGGis a standard SQL function implemented on Postgres, SQLite, MySQL, SQLite, Oracle, and MariaDB so if we were to include it in core it should be for all supported backends and not only for MariaDB.It should be trivial to implement by subclassing
Aggregatein fact I suspect that the following should work on most backends by defaultOr with subtle adjusted as using
json_group_arrayon SQLite.As for
StringAggwith a fallback onGROUP_CONCATon MySQL and MariaDB it is already being explored in #35444 which plans to add support for configurable support forORDER BYin aggregates.