Opened 7 months ago

Last modified 12 days 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: yes
Easy pickings: no UI/UX: no

Description (last modified by Robert Silén)

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 (13)

comment:1 by Robert Silén, 7 months ago

Description: modified (diff)

comment:2 by Robert Silén, 7 months ago

Description: modified (diff)

comment:3 by Simon Charette, 7 months ago

Component: UncategorizedDatabase layer (models, ORM)
Summary: ArrayAgg and others for MariaDBAdd support JSONArrayAgg
Triage Stage: UnreviewedAccepted

The contrib.postgres.ArrayAgg expression you pointed at uses Postgres arrays and MariaDB doesn't have native array support so they are not equivalent.

JSON_ARRAYAGG is 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 Aggregate in fact I suspect that the following should work on most backends by default

class JSONArrayAgg(Aggregate):
    function = "JSON_ARRAYAGG"
    output_field = JSONField()
    arity = 1

Or with subtle adjusted as using json_group_array on SQLite.

As for StringAgg with a fallback on GROUP_CONCAT on MySQL and MariaDB it is already being explored in #35444 which plans to add support for configurable support for ORDER BY in aggregates.

comment:4 by Lufafa Joshua, 6 months ago

Owner: changed from nobody to Lufafa Joshua
Status: newassigned

comment:5 by Hisham Mahmood, 6 months ago

Cc: Hisham Mahmood added

comment:6 by Lufafa Joshua, 6 months ago

Has patch: set
Last edited 5 months ago by Lufafa Joshua (previous) (diff)

comment:7 by Lufafa Joshua, 5 months ago

Needs documentation: set

comment:8 by Simon Charette, 5 months ago

Needs tests: set
Patch needs improvement: set

comment:9 by Lufafa Joshua, 3 months ago

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:10 by Sarah Boyce, 2 months ago

Patch needs improvement: set

comment:11 by Lufafa Joshua, 4 weeks ago

Patch needs improvement: unset

comment:12 by Sage Abdullah, 3 weeks ago

Cc: Sage Abdullah added

comment:13 by Sarah Boyce, 12 days ago

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top