r""" Create an :class:`.ExcludeConstraint` object. E.g.:: const = ExcludeConstraint( (Column("period"), "&&"), (Column("group"), "="), where=(Column("group") != "some group"), ops={"group": "my_operator_cla
(
self, *elements: Tuple[_DDLColumnArgument, str], **kw: Any
)
| 161 | class="st">":paramref:`.ExcludeConstraint.where`", |
| 162 | ) |
| 163 | def __init__( |
| 164 | self, *elements: Tuple[_DDLColumnArgument, str], **kw: Any |
| 165 | ) -> None: |
| 166 | rclass="st">""" |
| 167 | Create an :class:`.ExcludeConstraint` object. |
| 168 | |
| 169 | E.g.:: |
| 170 | |
| 171 | const = ExcludeConstraint( |
| 172 | (Column(class="st">"period"), class="st">"&&"), |
| 173 | (Column(class="st">"group"), class="st">"="), |
| 174 | where=(Column(class="st">"group") != class="st">"some group"), |
| 175 | ops={class="st">"group": class="st">"my_operator_class"}, |
| 176 | ) |
| 177 | |
| 178 | The constraint is normally embedded into the :class:`_schema.Table` |
| 179 | construct |
| 180 | directly, or added later using :meth:`.append_constraint`:: |
| 181 | |
| 182 | some_table = Table( |
| 183 | class="st">"some_table", |
| 184 | metadata, |
| 185 | Column(class="st">"id", Integer, primary_key=True), |
| 186 | Column(class="st">"period", TSRANGE()), |
| 187 | Column(class="st">"group", String), |
| 188 | ) |
| 189 | |
| 190 | some_table.append_constraint( |
| 191 | ExcludeConstraint( |
| 192 | (some_table.c.period, class="st">"&&"), |
| 193 | (some_table.c.group, class="st">"="), |
| 194 | where=some_table.c.group != class="st">"some group", |
| 195 | name=class="st">"some_table_excl_const", |
| 196 | ops={class="st">"group": class="st">"my_operator_class"}, |
| 197 | ) |
| 198 | ) |
| 199 | |
| 200 | The exclude constraint defined in this example requires the |
| 201 | ``btree_gist`` extension, that can be created using the |
| 202 | command ``CREATE EXTENSION btree_gist;``. |
| 203 | |
| 204 | :param \*elements: |
| 205 | |
| 206 | A sequence of two tuples of the form ``(column, operator)`` where |
| 207 | class="st">"column" is either a :class:`_schema.Column` object, or a SQL |
| 208 | expression element (e.g. ``func.int8range(table.from, table.to)``) |
| 209 | or the name of a column as string, and class="st">"operator" is a string |
| 210 | containing the operator to use (e.g. `class="st">"&&"` or `class="st">"="`). |
| 211 | |
| 212 | In order to specify a column name when a :class:`_schema.Column` |
| 213 | object is not available, while ensuring |
| 214 | that any necessary quoting rules take effect, an ad-hoc |
| 215 | :class:`_schema.Column` or :func:`_expression.column` |
| 216 | object should be used. |
| 217 | The ``column`` may also be a string SQL expression when |
| 218 | passed as :func:`_expression.literal_column` or |
| 219 | :func:`_expression.text` |
| 220 |