Anonymous avatar Anonymous committed bc625a3

add with_only_columns to Select to allow for removing columns from selects

Comments (0)

Files changed (1)

lib/sqlalchemy/sql/expression.py

         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."""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.