summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/ext.py
diff options
context:
space:
mode:
authorAlonM <alon.menczer@gmail.com>2020-11-15 08:13:25 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-11-16 14:02:49 -0500
commit018aa9870110ef97316e9984c7ecd7f3357b501a (patch)
tree2269fd252e87c83c4ad31925a7840124564871e1 /lib/sqlalchemy/dialects/postgresql/ext.py
parentbddb1070f9fa846233255fd0acd5316404560de1 (diff)
downloadsqlalchemy-018aa9870110ef97316e9984c7ecd7f3357b501a.tar.gz
Add opsclass to exclusion constraint
Added new parameter :paramref:`_postgresql.ExcludeConstraint.ops` to the :class:`_postgresql.ExcludeConstraint` object, to support operator class specification with this constraint. Pull request courtesy Alon Menczer. Fixes: #5604 Closes: #5700 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5700 Pull-request-sha: f8613e100792fc0bb3cf300ec6aebc78ecdf0361 Change-Id: Iaf664131ec84f8c2fb05edf799198b8d3bb83597
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/ext.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/ext.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/ext.py b/lib/sqlalchemy/dialects/postgresql/ext.py
index 78d9a96b6..4c8c3fc22 100644
--- a/lib/sqlalchemy/dialects/postgresql/ext.py
+++ b/lib/sqlalchemy/dialects/postgresql/ext.py
@@ -114,7 +114,8 @@ class ExcludeConstraint(ColumnCollectionConstraint):
const = ExcludeConstraint(
(Column('period'), '&&'),
(Column('group'), '='),
- where=(Column('group') != 'some group')
+ where=(Column('group') != 'some group'),
+ ops={'group': 'my_operator_class'}
)
The constraint is normally embedded into the :class:`_schema.Table`
@@ -133,7 +134,8 @@ class ExcludeConstraint(ColumnCollectionConstraint):
(some_table.c.period, '&&'),
(some_table.c.group, '='),
where=some_table.c.group != 'some group',
- name='some_table_excl_const'
+ name='some_table_excl_const',
+ ops={'group': 'my_operator_class'}
)
)
@@ -171,6 +173,19 @@ class ExcludeConstraint(ColumnCollectionConstraint):
If set, emit WHERE <predicate> when issuing DDL
for this constraint.
+ :param ops:
+ Optional dictionary. Used to define operator classes for the
+ elements; works the same way as that of the
+ :ref:`postgresql_ops <postgresql_operator_classes>`
+ parameter specified to the :class:`_schema.Index` construct.
+
+ .. versionadded:: 1.3.21
+
+ .. seealso::
+
+ :ref:`postgresql_operator_classes` - general description of how
+ PostgreSQL operator classes are specified.
+
"""
columns = []
render_exprs = []
@@ -209,6 +224,8 @@ class ExcludeConstraint(ColumnCollectionConstraint):
if where is not None:
self.where = coercions.expect(roles.StatementOptionRole, where)
+ self.ops = kw.get("ops", {})
+
def _set_parent(self, table, **kw):
super(ExcludeConstraint, self)._set_parent(table)