MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / Computed

Class Computed

lib/sqlalchemy/sql/schema.py:6417–6520  ·  view source on GitHub ↗

Defines a generated column, i.e. "GENERATED ALWAYS AS" syntax. The :class:`.Computed` construct is an inline construct added to the argument list of a :class:`_schema.Column` object:: from sqlalchemy import Computed Table( "square", metadata_obj,

Source from the content-addressed store, hash-verified

6415
6416
6417class Computed(FetchedValue, SchemaItem):
6418 """Defines a generated column, i.e. "GENERATED ALWAYS AS" syntax.
6419
6420 The :class:`.Computed` construct is an inline construct added to the
6421 argument list of a :class:`_schema.Column` object::
6422
6423 from sqlalchemy import Computed
6424
6425 Table(
6426 "square",
6427 metadata_obj,
6428 Column("side", Float, nullable=False),
6429 Column("area", Float, Computed("side * side")),
6430 )
6431
6432 See the linked documentation below for complete details.
6433
6434 .. seealso::
6435
6436 :ref:`computed_ddl`
6437
6438 """
6439
6440 __visit_name__ = "computed_column"
6441
6442 column: Optional[Column[Any]]
6443
6444 @_document_text_coercion(
6445 "sqltext", ":class:`.Computed`", ":paramref:`.Computed.sqltext`"
6446 )
6447 def __init__(
6448 self, sqltext: _DDLColumnArgument, persisted: Optional[bool] = None
6449 ) -> None:
6450 """Construct a GENERATED ALWAYS AS DDL construct to accompany a
6451 :class:`_schema.Column`.
6452
6453 :param sqltext:
6454 A string containing the column generation expression, which will be
6455 used verbatim, or a SQL expression construct, such as a
6456 :func:`_expression.text`
6457 object. If given as a string, the object is converted to a
6458 :func:`_expression.text` object.
6459
6460 :param persisted:
6461 Optional, controls how this column should be persisted by the
6462 database. Possible values are:
6463
6464 * ``None``, the default, it will use the default persistence
6465 defined by the database.
6466 * ``True``, will render ``GENERATED ALWAYS AS ... STORED``, or the
6467 equivalent for the target database if supported.
6468 * ``False``, will render ``GENERATED ALWAYS AS ... VIRTUAL``, or
6469 the equivalent for the target database if supported.
6470
6471 Specifying ``True`` or ``False`` may raise an error when the DDL
6472 is emitted to the target database if the database does not support
6473 that persistence option. Leaving this parameter at its default
6474 of ``None`` is guaranteed to succeed for all databases that support

Calls

no outgoing calls