[Sqlalchemy-tickets] Issue #3939: Alias as column expr needs tweak to self_group(), but don't know
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2017-03-16 13:38:56
|
New issue 3939: Alias as column expr needs tweak to self_group(), but don't know use case yet https://bitbucket.org/zzzeek/sqlalchemy/issues/3939/alias-as-column-expr-needs-tweak-to Michael Bayer: this produces nonsensical SQL, but putting Alias into a func is something they need for the Postgresql functions: ``` #!python from sqlalchemy import * t = table('t', column('x')) expr = func.foobar(select([t]).alias()) stmt = select([expr]) print stmt ``` self_group() fails because it does not provide for "against" since it never expected to be called in a column context: ``` #!diff diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index b69d667..9db1e08 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -1241,13 +1241,13 @@ class Alias(FromClause): or 'anon')) self.name = name - def self_group(self, target=None): - if isinstance(target, CompoundSelect) and \ + def self_group(self, against=None): + if isinstance(against, CompoundSelect) and \ isinstance(self.original, Select) and \ self.original._needs_parens_for_grouping(): return FromGrouping(self) - return super(Alias, self).self_group(target) + return super(Alias, self).self_group(against=against) @property def description(self): @@ -2269,7 +2269,7 @@ class CompoundSelect(GenerativeSelect): n + 1, len(s.c._all_columns)) ) - self.selects.append(s.self_group(self)) + self.selects.append(s.self_group(against=self)) GenerativeSelect.__init__(self, **kwargs) ``` still, the SQL from above is: ``` #!sql SELECT foobar(SELECT t.x FROM t) AS foobar_1 FROM (SELECT t.x AS x FROM t) AS anon_1 ``` so...I don't know yet what they are trying to make this do that makes any sense. |