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:
| 7034 | |
| 7035 | |
| 7036 | class ScalarSelect( |
| 7037 | roles.InElementRole, Generative, GroupedElement, ColumnElement[_T] |
| 7038 | ): |
| 7039 | """Represent a scalar subquery. |
| 7040 | |
| 7041 | |
| 7042 | A :class:`_sql.ScalarSelect` is created by invoking the |
| 7043 | :meth:`_sql.SelectBase.scalar_subquery` method. The object |
| 7044 | then participates in other SQL expressions as a SQL column expression |
| 7045 | within the :class:`_sql.ColumnElement` hierarchy. |
| 7046 | |
| 7047 | .. seealso:: |
| 7048 | |
| 7049 | :meth:`_sql.SelectBase.scalar_subquery` |
| 7050 | |
| 7051 | :ref:`tutorial_scalar_subquery` - in the 2.0 tutorial |
| 7052 | |
| 7053 | """ |
| 7054 | |
| 7055 | _traverse_internals: _TraverseInternalsType = [ |
| 7056 | ("element", InternalTraversal.dp_clauseelement), |
| 7057 | ("type", InternalTraversal.dp_type), |
| 7058 | ] |
| 7059 | |
| 7060 | _from_objects: List[FromClause] = [] |
| 7061 | _is_from_container = True |
| 7062 | if not TYPE_CHECKING: |
| 7063 | _is_implicitly_boolean = False |
| 7064 | inherit_cache = True |
| 7065 | |
| 7066 | element: SelectBase |
| 7067 | |
| 7068 | def __init__(self, element: SelectBase) -> None: |
| 7069 | self.element = element |
| 7070 | self.type = element._scalar_type() |
| 7071 | self._propagate_attrs = element._propagate_attrs |
| 7072 | |
| 7073 | def __getattr__(self, attr: str) -> Any: |
| 7074 | return getattr(self.element, attr) |
| 7075 | |
| 7076 | def __getstate__(self) -> Dict[str, Any]: |
| 7077 | return {"element": self.element, "type": self.type} |
| 7078 | |
| 7079 | def __setstate__(self, state: Dict[str, Any]) -> None: |
| 7080 | self.element = state["element"] |
| 7081 | self.type = state["type"] |
| 7082 | |
| 7083 | @property |
| 7084 | def columns(self) -> NoReturn: |
| 7085 | raise exc.InvalidRequestError( |
| 7086 | "Scalar Select expression has no " |
| 7087 | "columns; use this object directly " |
| 7088 | "within a column-level expression." |
| 7089 | ) |
| 7090 | |
| 7091 | c = columns |
| 7092 | |
| 7093 | @_generative |