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

Class ScalarSelect

lib/sqlalchemy/sql/selectable.py:6747–6891  ·  view source on GitHub ↗

Represent a scalar subquery. A :class:`_sql.ScalarSelect` is created by invoking the :meth:`_sql.SelectBase.scalar_subquery` method. The object then participates in other SQL expressions as a SQL column expression within the :class:`_sql.ColumnElement` hierarchy. .. seealso:

Source from the content-addressed store, hash-verified

6745
6746
6747class ScalarSelect(
6748 roles.InElementRole, Generative, GroupedElement, ColumnElement[_T]
6749):
6750 """Represent a scalar subquery.
6751
6752
6753 A :class:`_sql.ScalarSelect` is created by invoking the
6754 :meth:`_sql.SelectBase.scalar_subquery` method. The object
6755 then participates in other SQL expressions as a SQL column expression
6756 within the :class:`_sql.ColumnElement` hierarchy.
6757
6758 .. seealso::
6759
6760 :meth:`_sql.SelectBase.scalar_subquery`
6761
6762 :ref:`tutorial_scalar_subquery` - in the 2.0 tutorial
6763
6764 """
6765
6766 _traverse_internals: _TraverseInternalsType = [
6767 ("element", InternalTraversal.dp_clauseelement),
6768 ("type", InternalTraversal.dp_type),
6769 ]
6770
6771 _from_objects: List[FromClause] = []
6772 _is_from_container = True
6773 if not TYPE_CHECKING:
6774 _is_implicitly_boolean = False
6775 inherit_cache = True
6776
6777 element: SelectBase
6778
6779 def __init__(self, element: SelectBase) -> None:
6780 self.element = element
6781 self.type = element._scalar_type()
6782 self._propagate_attrs = element._propagate_attrs
6783
6784 def __getattr__(self, attr: str) -> Any:
6785 return getattr(self.element, attr)
6786
6787 def __getstate__(self) -> Dict[str, Any]:
6788 return {"element": self.element, "type": self.type}
6789
6790 def __setstate__(self, state: Dict[str, Any]) -> None:
6791 self.element = state["element"]
6792 self.type = state["type"]
6793
6794 @property
6795 def columns(self) -> NoReturn:
6796 raise exc.InvalidRequestError(
6797 "Scalar Select expression has no "
6798 "columns; use this object directly "
6799 "within a column-level expression."
6800 )
6801
6802 c = columns
6803
6804 @_generative

Callers 1

scalar_subqueryMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected