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

Method set_label_style

lib/sqlalchemy/orm/query.py:925–961  ·  view source on GitHub ↗

Apply column labels to the return value of Query.statement. Indicates that this Query's `statement` accessor should return a SELECT statement that applies labels to all columns in the form _ ; this is commonly used to disambiguate columns from m

(self, style: SelectLabelStyle)

Source from the content-addressed store, hash-verified

923 return self._label_style
924
925 def set_label_style(self, style: SelectLabelStyle) -> Self:
926 """Apply column labels to the return value of Query.statement.
927
928 Indicates that this Query's `statement` accessor should return
929 a SELECT statement that applies labels to all columns in the
930 form <tablename>_<columnname>; this is commonly used to
931 disambiguate columns from multiple tables which have the same
932 name.
933
934 When the `Query` actually issues SQL to load rows, it always
935 uses column labeling.
936
937 .. note:: The :meth:`_query.Query.set_label_style` method *only* applies
938 the output of :attr:`_query.Query.statement`, and *not* to any of
939 the result-row invoking systems of :class:`_query.Query` itself,
940 e.g.
941 :meth:`_query.Query.first`, :meth:`_query.Query.all`, etc.
942 To execute
943 a query using :meth:`_query.Query.set_label_style`, invoke the
944 :attr:`_query.Query.statement` using :meth:`.Session.execute`::
945
946 result = session.execute(
947 query.set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL).statement
948 )
949
950 .. versionadded:: 1.4
951
952
953 .. seealso::
954
955 :meth:`_sql.Select.set_label_style` - v2 equivalent method.
956
957 """ # noqa
958 if self._label_style is not style:
959 self = self._generate()
960 self._label_style = style
961 return self
962
963 @_generative
964 def enable_assertions(self, value: bool) -> Self:

Callers 15

with_labelsMethod · 0.95
_legacy_from_selfMethod · 0.95
_create_orm_contextMethod · 0.45
load_scalar_attributesFunction · 0.45
_subclass_load_via_inMethod · 0.45
_get_implMethod · 0.45
subqueryMethod · 0.45
__clause_element__Method · 0.45
existsMethod · 0.45

Calls 1

_generateMethod · 0.45