summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_array.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/postgres_tests/test_array.py')
-rw-r--r--tests/postgres_tests/test_array.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index 436838dd09..dff9a651c3 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -12,7 +12,12 @@ from django.core.management import call_command
from django.db import IntegrityError, connection, models
from django.db.models.expressions import Exists, OuterRef, RawSQL, Value
from django.db.models.functions import Cast, JSONObject, Upper
-from django.test import TransactionTestCase, modify_settings, override_settings
+from django.test import (
+ TransactionTestCase,
+ modify_settings,
+ override_settings,
+ skipUnlessDBFeature,
+)
from django.test.utils import isolate_apps
from django.utils import timezone
@@ -405,6 +410,27 @@ class TestQuerying(PostgreSQLTestCase):
expected,
)
+ @skipUnlessDBFeature("allows_group_by_refs")
+ def test_group_by_order_by_aliases(self):
+ with self.assertNumQueries(1) as ctx:
+ self.assertSequenceEqual(
+ NullableIntegerArrayModel.objects.filter(
+ field__0__isnull=False,
+ )
+ .values("field__0")
+ .annotate(arrayagg=ArrayAgg("id"))
+ .order_by("field__0"),
+ [
+ {"field__0": 1, "arrayagg": [1]},
+ {"field__0": 2, "arrayagg": [2, 3]},
+ {"field__0": 20, "arrayagg": [4]},
+ ],
+ )
+ alias = connection.ops.quote_name("field__0")
+ sql = ctx[0]["sql"]
+ self.assertIn(f"GROUP BY {alias}", sql)
+ self.assertIn(f"ORDER BY {alias}", sql)
+
def test_index(self):
self.assertSequenceEqual(
NullableIntegerArrayModel.objects.filter(field__0=2), self.objs[1:3]