diff options
| author | Grzegorz Makarewicz <mak@trisoft.com.pl> | 2015-10-02 00:23:57 +0200 |
|---|---|---|
| committer | Grzegorz Makarewicz <mak@trisoft.com.pl> | 2015-10-02 00:23:57 +0200 |
| commit | a6b78827fc12fdd65ee3f920b881ce398e99ee6c (patch) | |
| tree | 112cb2ac537bd3a5e191f270b3827611e7ff9aa3 /lib/sqlalchemy/sql/selectable.py | |
| parent | b341b988649633f75e750f0919bad77b2720799d (diff) | |
| parent | ac08920284935e7e7519ce77ba369703390155dc (diff) | |
| download | sqlalchemy-a6b78827fc12fdd65ee3f920b881ce398e99ee6c.tar.gz | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'lib/sqlalchemy/sql/selectable.py')
| -rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 245c54817..73341053d 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -224,7 +224,7 @@ class HasSuffixes(object): stmt = select([col1, col2]).cte().suffix_with( "cycle empno set y_cycle to 1 default 0", dialect="oracle") - Multiple prefixes can be specified by multiple calls + Multiple suffixes can be specified by multiple calls to :meth:`.suffix_with`. :param \*expr: textual or :class:`.ClauseElement` construct which @@ -1101,6 +1101,14 @@ class Alias(FromClause): or 'anon')) self.name = name + def self_group(self, target=None): + if isinstance(target, CompoundSelect) and \ + isinstance(self.original, Select) and \ + self.original._needs_parens_for_grouping(): + return FromGrouping(self) + + return super(Alias, self).self_group(target) + @property def description(self): if util.py3k: @@ -3208,6 +3216,13 @@ class Select(HasPrefixes, HasSuffixes, GenerativeSelect): return None return None + def _needs_parens_for_grouping(self): + return ( + self._limit_clause is not None or + self._offset_clause is not None or + bool(self._order_by_clause.clauses) + ) + def self_group(self, against=None): """return a 'grouping' construct as per the ClauseElement specification. @@ -3217,7 +3232,8 @@ class Select(HasPrefixes, HasSuffixes, GenerativeSelect): expressions and should not require explicit use. """ - if isinstance(against, CompoundSelect): + if isinstance(against, CompoundSelect) and \ + not self._needs_parens_for_grouping(): return self return FromGrouping(self) |
