MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / reduce_columns

Method reduce_columns

lib/sqlalchemy/sql/selectable.py:6247–6280  ·  view source on GitHub ↗

Return a new :func:`_expression.select` construct with redundantly named, equivalently-valued columns removed from the columns clause. "Redundant" here means two columns where one refers to the other either based on foreign key, or via a simple equality comparison in

(
        self, only_synonyms: bool = True
    )

Source from the content-addressed store, hash-verified

6245
6246 @util.preload_module("sqlalchemy.sql.util")
6247 def reduce_columns(
6248 self, only_synonyms: bool = True
6249 ) -> Select[Unpack[TupleAny]]:
6250 """Return a new :func:`_expression.select` construct with redundantly
6251 named, equivalently-valued columns removed from the columns clause.
6252
6253 "Redundant" here means two columns where one refers to the
6254 other either based on foreign key, or via a simple equality
6255 comparison in the WHERE clause of the statement. The primary purpose
6256 of this method is to automatically construct a select statement
6257 with all uniquely-named columns, without the need to use
6258 table-qualified labels as
6259 :meth:`_expression.Select.set_label_style`
6260 does.
6261
6262 When columns are omitted based on foreign key, the referred-to
6263 column is the one that's kept. When columns are omitted based on
6264 WHERE equivalence, the first column in the columns clause is the
6265 one that's kept.
6266
6267 :param only_synonyms: when True, limit the removal of columns
6268 to those which have the same name as the equivalent. Otherwise,
6269 all columns that are equivalent to another are removed.
6270
6271 """
6272 woc: Select[Unpack[TupleAny]]
6273 woc = self.with_only_columns(
6274 *util.preloaded.sql_util.reduce_columns(
6275 self._all_selected_columns,
6276 only_synonyms=only_synonyms,
6277 *(self._where_criteria + self._from_obj),
6278 )
6279 )
6280 return woc
6281
6282 # START OVERLOADED FUNCTIONS self.with_only_columns Select 1-8 ", *, maintain_column_froms: bool =..." # noqa: E501
6283

Calls 1

with_only_columnsMethod · 0.95