from ._typing import _ColumnExpressionArgument
from ._typing import _ColumnExpressionOrLiteralArgument
from ._typing import _ColumnExpressionOrStrLabelArgument
- from ._typing import _DMLOnlyColumnArgument
+ from ._typing import _OnlyColumnArgument
from ._typing import _TypeEngineArgument
from .elements import _FrameIntTuple
from .elements import BinaryExpression
return coercions.expect(roles.ExpressionElementRole, clause).__invert__()
-def from_dml_column(column: _DMLOnlyColumnArgument[_T]) -> DMLTargetCopy[_T]:
+def from_dml_column(column: _OnlyColumnArgument[_T]) -> DMLTargetCopy[_T]:
r"""A placeholder that may be used in compiled INSERT or UPDATE expressions
to refer to the SQL expression or value being applied to another column.
if TYPE_CHECKING:
from ._typing import _FromClauseArgument
from ._typing import _OnClauseArgument
+ from ._typing import _OnlyColumnArgument
from ._typing import _SelectStatementForCompoundArgument
from ._typing import _T0
from ._typing import _T1
def values(
- *columns: ColumnClause[Any],
+ *columns: _OnlyColumnArgument[Any],
name: Optional[str] = None,
literal_binds: bool = False,
) -> Values:
r"""Construct a :class:`_expression.Values` construct representing the
SQL ``VALUES`` clause.
-
The column expressions and the actual data for :class:`_expression.Values`
are given in two separate steps. The constructor receives the column
expressions typically as :func:`_expression.column` constructs, and the
_T9 = TypeVar("_T9", bound=Any)
+_OnlyColumnArgument = Union[
+ "ColumnElement[_T]",
+ _HasClauseElement[_T],
+ roles.DMLColumnRole,
+]
+"""A narrow type that is looking for a ColumnClause (e.g. table column with a
+name) or an ORM element that produces this.
+
+This is used for constructs that need a named column to represent a
+position in a selectable, like TextClause().columns() or values(...).
+
+"""
+
_ColumnExpressionArgument = Union[
"ColumnElement[_T]",
_HasClauseElement[_T],
"""
-_DMLOnlyColumnArgument = Union[
- _HasClauseElement[_T],
- roles.DMLColumnRole,
- "SQLCoreOperations[_T]",
-]
-
_DMLKey = TypeVar("_DMLKey", bound=_DMLColumnArgument)
_DMLColumnKeyMapping = Mapping[_DMLKey, Any]
from ._typing import _DDLColumnArgument
from ._typing import _DMLTableArgument
from ._typing import _FromClauseArgument
+ from ._typing import _OnlyColumnArgument
from .base import SyntaxExtension
from .dml import _DMLTableElement
from .elements import BindParameter
@overload
def expect(
role: Type[roles.LabeledColumnExprRole[Any]],
- element: _ColumnExpressionArgument[_T],
+ element: _ColumnExpressionArgument[_T] | _OnlyColumnArgument[_T],
**kw: Any,
) -> NamedColumn[_T]: ...
from ._typing import _ByArgument
from ._typing import _ColumnExpressionArgument
from ._typing import _ColumnExpressionOrStrLabelArgument
- from ._typing import _DMLOnlyColumnArgument
from ._typing import _HasDialect
from ._typing import _InfoType
+ from ._typing import _OnlyColumnArgument
from ._typing import _PropagateAttrsType
from ._typing import _TypeEngineArgument
from .base import _EntityNamespace
"""
- def __init__(self, column: _DMLOnlyColumnArgument[_T]):
+ def __init__(self, column: _OnlyColumnArgument[_T]):
self.column = coercions.expect(roles.ColumnArgumentRole, column)
self.type = self.column.type
@util.preload_module("sqlalchemy.sql.selectable")
def columns(
self,
- *cols: _ColumnExpressionArgument[Any],
+ *cols: _OnlyColumnArgument[Any],
**types: _TypeEngineArgument[Any],
) -> TextualSelect:
r"""Turn this :class:`_expression.AbstractTextClause` object into a
from ._typing import _MAYBE_ENTITY
from ._typing import _NOT_ENTITY
from ._typing import _OnClauseArgument
+ from ._typing import _OnlyColumnArgument
from ._typing import _SelectStatementForCompoundArgument
from ._typing import _T0
from ._typing import _T1
__visit_name__ = "values"
_data: Tuple[Sequence[Tuple[Any, ...]], ...] = ()
+ _column_args: Tuple[NamedColumn[Any], ...]
_unnamed: bool
_traverse_internals: _TraverseInternalsType = [
def __init__(
self,
- *columns: ColumnClause[Any],
+ *columns: _OnlyColumnArgument[Any],
name: Optional[str] = None,
literal_binds: bool = False,
):
super().__init__()
- self._column_args = columns
+ self._column_args = tuple(
+ coercions.expect(roles.LabeledColumnExprRole, col)
+ for col in columns
+ )
if name is None:
self._unnamed = True
def __init__(
self,
- columns: Sequence[ColumnClause[Any]],
+ columns: Sequence[NamedColumn[Any]],
data: Tuple[Sequence[Tuple[Any, ...]], ...],
literal_binds: bool,
):
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy import update
+from sqlalchemy import values
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
stmt6 = user_table.update().values(
{user_table.c.d: 123, user_table.c.data: "value"}
)
+
+
+update_values = values(
+ User.id,
+ User.name,
+ name="update_values",
+).data([(1, "Alice"), (2, "Bob")])
+
+query = (
+ update(User)
+ .values(
+ {
+ User.name: update_values.c.name,
+ }
+ )
+ .where(User.id == update_values.c.id)
+)