#36638: The default for ArrayAgg should be an empty list rather than None
-------------------------------------+-------------------------------------
Reporter: Markus Amalthea | Owner: (none)
Magnuson |
Type: Uncategorized | Status: closed
Component: contrib.postgres | Version: 5.2
Severity: Normal | Resolution: invalid
Keywords: ArrayAgg | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
In other words, the `ARRAY_AGG` Postgres function returns `NULL`
[https://www.postgresql.org/docs/current/functions-aggregate.html on an
empty set].
Passing `default=[]` wraps the `ARRAY_AGG` in `COALESCE` to default to the
provided value
{{{#!sql
SELECT COALESCE(ARRAY_AGG(field), '{}'::text[])
}}}
Per Postgres documentation linked above
> It should be noted that except for `count`, these functions return a
null value when no rows are selected. In particular, `sum` of no rows
returns null, not zero as one might expect, and `array_agg` returns null
rather than an empty array when there are no input rows. The `coalesce`
function can be used to substitute zero or an empty array for null when
necessary.
--
Ticket URL: <https://code.djangoproject.com/ticket/36638#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 visit
https://groups.google.com/d/msgid/django-updates/01070199ab29953f-65750b52-a58f-468a-a83a-49eb73194295-000000%40eu-central-1.amazonses.com.