﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32776	Support Array subqueries on PostgreSQL	Hannes Ljungberg	Hannes Ljungberg	"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"	New feature	closed	contrib.postgres	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
