MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / reduce_columns

Method reduce_columns

lib/sqlalchemy/sql/selectable.py:5990–6021  ·  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

5988
5989 @util.preload_module("sqlalchemy.sql.util")
5990 def reduce_columns(self, only_synonyms: bool = True) -> Select[Any]:
5991 """Return a new :func:`_expression.select` construct with redundantly
5992 named, equivalently-valued columns removed from the columns clause.
5993
5994 "Redundant" here means two columns where one refers to the
5995 other either based on foreign key, or via a simple equality
5996 comparison in the WHERE clause of the statement. The primary purpose
5997 of this method is to automatically construct a select statement
5998 with all uniquely-named columns, without the need to use
5999 table-qualified labels as
6000 :meth:`_expression.Select.set_label_style`
6001 does.
6002
6003 When columns are omitted based on foreign key, the referred-to
6004 column is the one that's kept. When columns are omitted based on
6005 WHERE equivalence, the first column in the columns clause is the
6006 one that's kept.
6007
6008 :param only_synonyms: when True, limit the removal of columns
6009 to those which have the same name as the equivalent. Otherwise,
6010 all columns that are equivalent to another are removed.
6011
6012 """
6013 woc: Select[Any]
6014 woc = self.with_only_columns(
6015 *util.preloaded.sql_util.reduce_columns(
6016 self._all_selected_columns,
6017 only_synonyms=only_synonyms,
6018 *(self._where_criteria + self._from_obj),
6019 )
6020 )
6021 return woc
6022
6023 # START OVERLOADED FUNCTIONS self.with_only_columns Select 1-8 ", *, maintain_column_froms: bool =..." # noqa: E501
6024

Calls 1

with_only_columnsMethod · 0.95