diff options
author | Ants Aasma <ants.aasma@gmail.com> | 2008-05-29 02:11:59 +0000 |
---|---|---|
committer | Ants Aasma <ants.aasma@gmail.com> | 2008-05-29 02:11:59 +0000 |
commit | 4cccb5022818fc93e357c69ddb15e31fc3177ada (patch) | |
tree | 41ff8d2d67a9605bd1de0430191f80bc81fc2be4 /lib/sqlalchemy/sql/expression.py | |
parent | 77c308367ffec3e8af9b5463b1c3bdd89640e8ac (diff) | |
download | sqlalchemy-4cccb5022818fc93e357c69ddb15e31fc3177ada.tar.gz |
add with_only_columns to Select to allow for removing columns from selects
Diffstat (limited to 'lib/sqlalchemy/sql/expression.py')
-rw-r--r-- | lib/sqlalchemy/sql/expression.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index a644582db..bf848654c 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -3084,6 +3084,16 @@ class Select(_SelectBaseMixin, FromClause): s._froms = s._froms.union(_from_objects(column)) return s + def with_only_columns(self, columns): + """return a new select() construct with its columns clause replaced with the given columns.""" + s = self._generate() + s._raw_columns = [ + isinstance(c, _ScalarSelect) and c.self_group(against=operators.comma_op) or c + for c in + [_literal_as_column(c) for c in columns] + ] + return s + def where(self, whereclause): """return a new select() construct with the given expression added to its WHERE clause, joined to the existing clause via AND, if any.""" |