for expr, name, op in constraint._render_exprs:
kw["include_table"] = False
exclude_element = self.sql_compiler.process(expr, **kw) + (
- (" " + constraint.ops[expr.key] + " ")
+ (" " + constraint.ops[expr.key])
if hasattr(expr, "key") and expr.key in constraint.ops
else ""
)
if where is not None:
self.where = coercions.expect(roles.StatementOptionRole, where)
- # TODO: add docs, name?
- self.ops = kw.get("ops")
+ self.ops = kw.get("ops", {})
def _set_parent(self, table, **kw):
super(ExcludeConstraint, self)._set_parent(table)
where="room > 100",
deferrable=True,
initially="immediate",
+ ops={"room": "my_opclass"},
)
tbl.append_constraint(cons)
self.assert_compile(
schema.AddConstraint(cons),
"ALTER TABLE testtbl ADD CONSTRAINT my_name "
"EXCLUDE USING gist "
- "(room WITH =, during WITH "
+ "(room my_opclass WITH =, during WITH "
"&&) WHERE "
"(room > 100) DEFERRABLE INITIALLY immediate",
dialect=postgresql.dialect(),
dialect=postgresql.dialect(),
)
+ def test_exclude_constraint_ops_many(self):
+ m = MetaData()
+ tbl = Table(
+ "testtbl", m, Column("room", String), Column("during", TSRANGE)
+ )
+ cons = ExcludeConstraint(
+ ("room", "="),
+ ("during", "&&"),
+ ops={"room": "first_opsclass", "during": "second_opclass"},
+ )
+ tbl.append_constraint(cons)
+ self.assert_compile(
+ schema.AddConstraint(cons),
+ "ALTER TABLE testtbl ADD EXCLUDE USING gist "
+ "(room first_opsclass WITH =, during second_opclass WITH &&)",
+ dialect=postgresql.dialect(),
+ )
+
def test_substring(self):
self.assert_compile(
func.substring("abc", 1, 2),