Fixed #32693 -- Quoted and lowercased generated column aliases.
This commit is contained in:
parent
071cf68630
commit
8de4ca74ba
|
@ -554,7 +554,10 @@ class SQLCompiler:
|
||||||
if alias:
|
if alias:
|
||||||
s_sql = '%s AS %s' % (s_sql, self.connection.ops.quote_name(alias))
|
s_sql = '%s AS %s' % (s_sql, self.connection.ops.quote_name(alias))
|
||||||
elif with_col_aliases:
|
elif with_col_aliases:
|
||||||
s_sql = '%s AS %s' % (s_sql, 'Col%d' % col_idx)
|
s_sql = '%s AS %s' % (
|
||||||
|
s_sql,
|
||||||
|
self.connection.ops.quote_name('col%d' % col_idx),
|
||||||
|
)
|
||||||
col_idx += 1
|
col_idx += 1
|
||||||
params.extend(s_params)
|
params.extend(s_params)
|
||||||
out_cols.append(s_sql)
|
out_cols.append(s_sql)
|
||||||
|
|
|
@ -7,7 +7,7 @@ from threading import Lock
|
||||||
|
|
||||||
from django.core.exceptions import EmptyResultSet, FieldError
|
from django.core.exceptions import EmptyResultSet, FieldError
|
||||||
from django.db import DEFAULT_DB_ALIAS, connection
|
from django.db import DEFAULT_DB_ALIAS, connection
|
||||||
from django.db.models import Count, Exists, F, OuterRef, Q
|
from django.db.models import Count, Exists, F, Max, OuterRef, Q
|
||||||
from django.db.models.expressions import RawSQL
|
from django.db.models.expressions import RawSQL
|
||||||
from django.db.models.sql.constants import LOUTER
|
from django.db.models.sql.constants import LOUTER
|
||||||
from django.db.models.sql.where import NothingNode, WhereNode
|
from django.db.models.sql.where import NothingNode, WhereNode
|
||||||
|
@ -1855,6 +1855,17 @@ class Queries6Tests(TestCase):
|
||||||
[self.t5, self.t4],
|
[self.t5, self.t4],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_col_alias_quoted(self):
|
||||||
|
with CaptureQueriesContext(connection) as captured_queries:
|
||||||
|
self.assertEqual(
|
||||||
|
Tag.objects.values('parent').annotate(
|
||||||
|
tag_per_parent=Count('pk'),
|
||||||
|
).aggregate(Max('tag_per_parent')),
|
||||||
|
{'tag_per_parent__max': 2},
|
||||||
|
)
|
||||||
|
sql = captured_queries[0]['sql']
|
||||||
|
self.assertIn('AS %s' % connection.ops.quote_name('col1'), sql)
|
||||||
|
|
||||||
|
|
||||||
class RawQueriesTests(TestCase):
|
class RawQueriesTests(TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in New Issue