]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add opsclass to exclusion constraint
authorAlonM <alon.menczer@gmail.com>
Sat, 14 Nov 2020 15:52:21 +0000 (17:52 +0200)
committerAlonM <alon.menczer@gmail.com>
Sat, 14 Nov 2020 15:52:21 +0000 (17:52 +0200)
lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/dialects/postgresql/ext.py

index d738393e78794dd9672bb0a6e82e6c29f17cd81d..772f9f553cd8be2ceb7889216b8f1b16e67deb81 100644 (file)
@@ -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
index 78d9a96b6787f089f5e605c6ca96df2e41f0b836..42e1a5c70fce0f85febc3869175e775fbe02f52b 100644 (file)
@@ -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)