diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-06-22 06:10:54 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-06-22 06:28:42 +0200 |
| commit | e07609a0d1cac573890380ee32b85d7743632650 (patch) | |
| tree | be5098e10e8f1332a1c82bfdd479295928e811a5 /tests/db_functions | |
| parent | b69b0c3fe871167a0ca01bb439508e335143801f (diff) | |
Refs #32858, Refs #32392 -- Restored using :: shortcut syntax in Cast() on PostgreSQL.
This partly reverts commit fdfbc66331292def201c9344e3cd29fbcbcd076a
unnecessary since b69b0c3fe871167a0ca01bb439508e335143801f.
Diffstat (limited to 'tests/db_functions')
| -rw-r--r-- | tests/db_functions/comparison/test_cast.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/db_functions/comparison/test_cast.py b/tests/db_functions/comparison/test_cast.py index 687cf77656..ffba8af316 100644 --- a/tests/db_functions/comparison/test_cast.py +++ b/tests/db_functions/comparison/test_cast.py @@ -1,9 +1,11 @@ import datetime import decimal +import unittest from django.db import connection, models from django.db.models.functions import Cast from django.test import TestCase, ignore_warnings, skipUnlessDBFeature +from django.test.utils import CaptureQueriesContext from ..models import Author, DTModel, Fan, FloatModel @@ -125,5 +127,20 @@ class CastTests(TestCase): self.assertIsInstance(cast_float, float) self.assertEqual(cast_float, 0.125) + @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL test') + def test_expression_wrapped_with_parentheses_on_postgresql(self): + """ + The SQL for the Cast expression is wrapped with parentheses in case + it's a complex expression. + """ + with CaptureQueriesContext(connection) as captured_queries: + list(Author.objects.annotate( + cast_float=Cast(models.Avg('age'), models.FloatField()), + )) + self.assertIn( + '(AVG("db_functions_author"."age"))::double precision', + captured_queries[0]['sql'], + ) + def test_cast_to_text_field(self): self.assertEqual(Author.objects.values_list(Cast('age', models.TextField()), flat=True).get(), '1') |
