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

Class CheckConstraint

lib/sqlalchemy/sql/schema.py:4475–4583  ·  view source on GitHub ↗

A table- or column-level CHECK constraint. Can be included in the definition of a Table or Column.

Source from the content-addressed store, hash-verified

4473
4474
4475class CheckConstraint(ColumnCollectionConstraint):
4476 """A table- or column-level CHECK constraint.
4477
4478 Can be included in the definition of a Table or Column.
4479 """
4480
4481 _allow_multiple_tables = True
4482
4483 __visit_name__ = "table_or_column_check_constraint"
4484
4485 @_document_text_coercion(
4486 "sqltext",
4487 ":class:`.CheckConstraint`",
4488 ":paramref:`.CheckConstraint.sqltext`",
4489 )
4490 def __init__(
4491 self,
4492 sqltext: _TextCoercedExpressionArgument[Any],
4493 name: _ConstraintNameArgument = None,
4494 deferrable: Optional[bool] = None,
4495 initially: Optional[str] = None,
4496 table: Optional[Table] = None,
4497 info: Optional[_InfoType] = None,
4498 _create_rule: Optional[Any] = None,
4499 _autoattach: bool = True,
4500 _type_bound: bool = False,
4501 **dialect_kw: Any,
4502 ) -> None:
4503 r"""Construct a CHECK constraint.
4504
4505 :param sqltext:
4506 A string containing the constraint definition, which will be used
4507 verbatim, or a SQL expression construct. If given as a string,
4508 the object is converted to a :func:`_expression.text` object.
4509 If the textual
4510 string includes a colon character, escape this using a backslash::
4511
4512 CheckConstraint(r"foo ~ E'a(?\:b|c)d")
4513
4514 :param name:
4515 Optional, the in-database name of the constraint.
4516
4517 :param deferrable:
4518 Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when
4519 issuing DDL for this constraint.
4520
4521 :param initially:
4522 Optional string. If set, emit INITIALLY <value> when issuing DDL
4523 for this constraint.
4524
4525 :param info: Optional data dictionary which will be populated into the
4526 :attr:`.SchemaItem.info` attribute of this object.
4527
4528 """
4529
4530 self.sqltext = coercions.expect(roles.DDLExpressionRole, sqltext)
4531 columns: List[Column[Any]] = []
4532 visitors.traverse(self.sqltext, {}, {"column": columns.append})

Calls

no outgoing calls