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,
| 5960 | |
| 5961 | |
| 5962 | class Computed(FetchedValue, SchemaItem): |
| 5963 | """Defines a generated column, i.e. "GENERATED ALWAYS AS" syntax. |
| 5964 | |
| 5965 | The :class:`.Computed` construct is an inline construct added to the |
| 5966 | argument list of a :class:`_schema.Column` object:: |
| 5967 | |
| 5968 | from sqlalchemy import Computed |
| 5969 | |
| 5970 | Table( |
| 5971 | "square", |
| 5972 | metadata_obj, |
| 5973 | Column("side", Float, nullable=False), |
| 5974 | Column("area", Float, Computed("side * side")), |
| 5975 | ) |
| 5976 | |
| 5977 | See the linked documentation below for complete details. |
| 5978 | |
| 5979 | .. versionadded:: 1.3.11 |
| 5980 | |
| 5981 | .. seealso:: |
| 5982 | |
| 5983 | :ref:`computed_ddl` |
| 5984 | |
| 5985 | """ |
| 5986 | |
| 5987 | __visit_name__ = "computed_column" |
| 5988 | |
| 5989 | column: Optional[Column[Any]] |
| 5990 | |
| 5991 | @_document_text_coercion( |
| 5992 | "sqltext", ":class:`.Computed`", ":paramref:`.Computed.sqltext`" |
| 5993 | ) |
| 5994 | def __init__( |
| 5995 | self, sqltext: _DDLColumnArgument, persisted: Optional[bool] = None |
| 5996 | ) -> None: |
| 5997 | """Construct a GENERATED ALWAYS AS DDL construct to accompany a |
| 5998 | :class:`_schema.Column`. |
| 5999 | |
| 6000 | :param sqltext: |
| 6001 | A string containing the column generation expression, which will be |
| 6002 | used verbatim, or a SQL expression construct, such as a |
| 6003 | :func:`_expression.text` |
| 6004 | object. If given as a string, the object is converted to a |
| 6005 | :func:`_expression.text` object. |
| 6006 | |
| 6007 | :param persisted: |
| 6008 | Optional, controls how this column should be persisted by the |
| 6009 | database. Possible values are: |
| 6010 | |
| 6011 | * ``None``, the default, it will use the default persistence |
| 6012 | defined by the database. |
| 6013 | * ``True``, will render ``GENERATED ALWAYS AS ... STORED``, or the |
| 6014 | equivalent for the target database if supported. |
| 6015 | * ``False``, will render ``GENERATED ALWAYS AS ... VIRTUAL``, or |
| 6016 | the equivalent for the target database if supported. |
| 6017 | |
| 6018 | Specifying ``True`` or ``False`` may raise an error when the DDL |
| 6019 | is emitted to the target database if the database does not support |
no outgoing calls