From a85e2ee3114e985d322d66a1f19a2179c607c62b Mon Sep 17 00:00:00 2001 From: AlonM Date: Sat, 14 Nov 2020 17:52:21 +0200 Subject: [PATCH] Add opsclass to exclusion constraint --- lib/sqlalchemy/dialects/postgresql/base.py | 8 ++++++-- lib/sqlalchemy/dialects/postgresql/ext.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index d738393e78..772f9f553c 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -2417,9 +2417,13 @@ class PGDDLCompiler(compiler.DDLCompiler): elements = [] for expr, name, op in constraint._render_exprs: kw["include_table"] = False - elements.append( - "%s WITH %s" % (self.sql_compiler.process(expr, **kw), op) + exclude_element = self.sql_compiler.process(expr, **kw) + ( + (" " + constraint.ops[expr.key] + " ") + if hasattr(expr, "key") and expr.key in constraint.ops + else "" ) + + elements.append("%s WITH %s" % (exclude_element, op)) text += "EXCLUDE USING %s (%s)" % ( self.preparer.validate_sql_phrase( constraint.using, IDX_USING diff --git a/lib/sqlalchemy/dialects/postgresql/ext.py b/lib/sqlalchemy/dialects/postgresql/ext.py index 78d9a96b67..42e1a5c70f 100644 --- a/lib/sqlalchemy/dialects/postgresql/ext.py +++ b/lib/sqlalchemy/dialects/postgresql/ext.py @@ -209,6 +209,9 @@ class ExcludeConstraint(ColumnCollectionConstraint): if where is not None: self.where = coercions.expect(roles.StatementOptionRole, where) + # TODO: add docs, name? + self.ops = kw.get("ops") + def _set_parent(self, table, **kw): super(ExcludeConstraint, self)._set_parent(table) -- 2.47.3