diff options
| author | Simon Charette <charette.s@gmail.com> | 2022-11-15 00:15:25 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-11-15 10:48:14 +0100 |
| commit | 7adb0c8b6008c30cd1d47ba076da4bdbdb4595fe (patch) | |
| tree | 35dc99c3f8605c4215d20cdf70335715e063ed2c /django/db/models/sql | |
| parent | 7a5307974ac18d1e9f35ac5754414479395f6a83 (diff) | |
Avoided unnecessary usage of RawSQL.
This ensures proper alias quoting.
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/compiler.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 170bde1d42..16b0bdad70 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -441,11 +441,11 @@ class SQLCompiler: # Add column used in ORDER BY clause to the selected # columns and to each combined query. order_by_idx = len(self.query.select) + 1 - col_name = f"__orderbycol{order_by_idx}" + col_alias = f"__orderbycol{order_by_idx}" for q in self.query.combined_queries: - q.add_annotation(expr_src, col_name) - self.query.add_select_col(resolved, col_name) - resolved.set_source_expressions([RawSQL(f"{order_by_idx}", ())]) + q.add_annotation(expr_src, col_alias) + self.query.add_select_col(resolved, col_alias) + resolved.set_source_expressions([Ref(col_alias, src)]) sql, params = self.compile(resolved) # Don't add the same column twice, but the order direction is # not taken into account so we strip it. When this entire method |
