A table- or column-level CHECK constraint. Can be included in the definition of a Table or Column.
| 4853 | |
| 4854 | |
| 4855 | class CheckConstraint(ColumnCollectionConstraint): |
| 4856 | """A table- or column-level CHECK constraint. |
| 4857 | |
| 4858 | Can be included in the definition of a Table or Column. |
| 4859 | """ |
| 4860 | |
| 4861 | _allow_multiple_tables = True |
| 4862 | |
| 4863 | __visit_name__ = "table_or_column_check_constraint" |
| 4864 | |
| 4865 | @_document_text_coercion( |
| 4866 | "sqltext", |
| 4867 | ":class:`.CheckConstraint`", |
| 4868 | ":paramref:`.CheckConstraint.sqltext`", |
| 4869 | ) |
| 4870 | def __init__( |
| 4871 | self, |
| 4872 | sqltext: _TextCoercedExpressionArgument[Any], |
| 4873 | name: _ConstraintNameArgument = None, |
| 4874 | deferrable: Optional[bool] = None, |
| 4875 | initially: Optional[str] = None, |
| 4876 | table: Optional[Table] = None, |
| 4877 | info: Optional[_InfoType] = None, |
| 4878 | _create_rule: Optional[Any] = None, |
| 4879 | _autoattach: bool = True, |
| 4880 | _type_bound: bool = False, |
| 4881 | **dialect_kw: Any, |
| 4882 | ) -> None: |
| 4883 | r"""Construct a CHECK constraint. |
| 4884 | |
| 4885 | :param sqltext: |
| 4886 | A string containing the constraint definition, which will be used |
| 4887 | verbatim, or a SQL expression construct. If given as a string, |
| 4888 | the object is converted to a :func:`_expression.text` object. |
| 4889 | If the textual |
| 4890 | string includes a colon character, escape this using a backslash:: |
| 4891 | |
| 4892 | CheckConstraint(r"foo ~ E'a(?\:b|c)d") |
| 4893 | |
| 4894 | :param name: |
| 4895 | Optional, the in-database name of the constraint. |
| 4896 | |
| 4897 | :param deferrable: |
| 4898 | Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when |
| 4899 | issuing DDL for this constraint. |
| 4900 | |
| 4901 | :param initially: |
| 4902 | Optional string. If set, emit INITIALLY <value> when issuing DDL |
| 4903 | for this constraint. |
| 4904 | |
| 4905 | :param info: Optional data dictionary which will be populated into the |
| 4906 | :attr:`.SchemaItem.info` attribute of this object. |
| 4907 | |
| 4908 | """ |
| 4909 | |
| 4910 | self.sqltext = coercions.expect(roles.DDLExpressionRole, sqltext) |
| 4911 | columns: List[Column[Any]] = [] |
| 4912 | visitors.traverse(self.sqltext, {}, {"column": columns.append}) |
no outgoing calls