summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/elements.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r--lib/sqlalchemy/sql/elements.py37
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index b6462b334..78c434cff 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -4263,7 +4263,11 @@ class ColumnClause(roles.LabeledColumnExprRole, Immutable, ColumnElement):
def _render_label_in_columns_clause(self):
return self.table is not None
- def _gen_label(self, name):
+ @property
+ def _ddl_label(self):
+ return self._gen_label(self.name, dedupe_on_key=False)
+
+ def _gen_label(self, name, dedupe_on_key=True):
t = self.table
if self.is_literal:
@@ -4287,21 +4291,22 @@ class ColumnClause(roles.LabeledColumnExprRole, Immutable, ColumnElement):
assert not isinstance(label, quoted_name)
label = quoted_name(label, t.name.quote)
- # ensure the label name doesn't conflict with that
- # of an existing column. note that this implies that any
- # Column must **not** set up its _label before its parent table
- # has all of its other Column objects set up. There are several
- # tables in the test suite which will fail otherwise; example:
- # table "owner" has columns "name" and "owner_name". Therefore
- # column owner.name cannot use the label "owner_name", it has
- # to be "owner_name_1".
- if label in t.c:
- _label = label
- counter = 1
- while _label in t.c:
- _label = label + "_" + str(counter)
- counter += 1
- label = _label
+ if dedupe_on_key:
+ # ensure the label name doesn't conflict with that of an
+ # existing column. note that this implies that any Column
+ # must **not** set up its _label before its parent table has
+ # all of its other Column objects set up. There are several
+ # tables in the test suite which will fail otherwise; example:
+ # table "owner" has columns "name" and "owner_name". Therefore
+ # column owner.name cannot use the label "owner_name", it has
+ # to be "owner_name_1".
+ if label in t.c:
+ _label = label
+ counter = 1
+ while _label in t.c:
+ _label = label + "_" + str(counter)
+ counter += 1
+ label = _label
return coercions.expect(roles.TruncatedLabelRole, label)