[Django] #32776: Support Array subqueries on PostgreSQL

155 views
Skip to first unread message

Django

unread,
May 23, 2021, 6:44:49 AM5/23/21
to django-...@googlegroups.com
#32776: Support Array subqueries on PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Hannes | Owner: Hannes Ljungberg
Ljungberg |
Type: New | Status: assigned
feature |
Component: | Version: dev
contrib.postgres |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I think we should support [https://www.postgresql.org/docs/current/sql-
expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS constructing arrays in
PostgreSQL]() without requiring aggregation through `array_agg()`. This
can be done by correlated subqueries by passing a subquery to the `ARRAY`
constructor. In its simplest form it could look something like this:
{{{
class ArraySubquery(Subquery):
template = 'ARRAY(%(subquery)s)'
}}}

Currently all subqueries get their ordering cleared if they aren't
fulfilling some conditions like being sliced and using distinct fields.
This would need to be refactored to enable array subqueries since the
ordering matters due to the subquery producing an array.

There've been a couple of tickets related to this:
https://code.djangoproject.com/ticket/31687
https://code.djangoproject.com/ticket/32658

[https://code.djangoproject.com/ticket/32658#comment:4 Simons suggestion]
to move the clearing of ordering from `Query.resolve_expression` to
`In(Lookup).process_rhs` seems like a good idea to me.

I also think that adding support for array subqueries would help in
resolving this ticket: https://code.djangoproject.com/ticket/26056

--
Ticket URL: <https://code.djangoproject.com/ticket/32776>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 23, 2021, 12:39:21 PM5/23/21
to django-...@googlegroups.com
#32776: Support Array subqueries on PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes
| Ljungberg
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted


Comment:

Another edge case that came to mind is that we also likely want to keep
clearing ordering when doing existence checks so it should only be cleared
when using

1. `filter(field__in=query)`
2. `Exists`
3. `Queryset.exists()`

--
Ticket URL: <https://code.djangoproject.com/ticket/32776#comment:1>

Django

unread,
Jun 30, 2021, 5:05:45 PM6/30/21
to django-...@googlegroups.com
#32776: Support Array subqueries on PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes
| Ljungberg
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hannes Ljungberg):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/14575

--
Ticket URL: <https://code.djangoproject.com/ticket/32776#comment:2>

Django

unread,
Jul 5, 2021, 4:12:51 AM7/5/21
to django-...@googlegroups.com
#32776: Support Array subqueries on PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes
| Ljungberg
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32776#comment:3>

Django

unread,
Jul 5, 2021, 4:39:12 PM7/5/21
to django-...@googlegroups.com
#32776: Support Array subqueries on PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes
| Ljungberg
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hannes Ljungberg):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/32776#comment:4>

Django

unread,
Jul 6, 2021, 1:38:48 AM7/6/21
to django-...@googlegroups.com
#32776: Support Array subqueries on PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes
| Ljungberg
Type: New feature | Status: assigned
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32776#comment:5>

Django

unread,
Jul 6, 2021, 2:13:59 AM7/6/21
to django-...@googlegroups.com
#32776: Support Array subqueries on PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Hannes Ljungberg | Owner: Hannes
| Ljungberg
Type: New feature | Status: closed
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"a06b977a91f043c509df781670fb4cf35cb437b7" a06b977a]:
{{{
#!CommitTicketReference repository=""
revision="a06b977a91f043c509df781670fb4cf35cb437b7"
Fixed #32776 -- Added support for Array subqueries on PostgreSQL.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32776#comment:6>

Reply all
Reply to author
Forward
0 new messages