summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_array.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2022-09-22 23:57:06 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-10-06 09:34:31 +0200
commit04518e310d4552ff7595a34f5a7f93487d78a406 (patch)
tree0cb94a0dfc2b8c63d3da0ceb90d41b048b067695 /tests/postgres_tests/test_array.py
parentc58a8acd413ccc992dd30afd98ed900897e1f719 (diff)
downloaddjango-04518e310d4552ff7595a34f5a7f93487d78a406.tar.gz
Refs #33308 -- Enabled explicit GROUP BY and ORDER BY aliases.
This ensures explicit grouping from using values() before annotating an aggregate function groups by selected aliases if supported. The GROUP BY feature is disabled on Oracle because it doesn't support it.
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]