constraint
)
elements = []
+ kw["include_table"] = False
+ kw["literal_binds"] = True
for expr, name, op in constraint._render_exprs:
- kw["include_table"] = False
exclude_element = self.sql_compiler.process(expr, **kw) + (
(" " + constraint.ops[expr.key])
if hasattr(expr, "key") and expr.key in constraint.ops
:param \*elements:
A sequence of two tuples of the form ``(column, operator)`` where
- "column" is a SQL expression element or a raw SQL string, most
- typically a :class:`_schema.Column` object,
- and "operator" is a string
- containing the operator to use. In order to specify a column name
- when a :class:`_schema.Column` object is not available,
- while ensuring
+ "column" is a SQL expression element or the name of a column as
+ string, most typically a :class:`_schema.Column` object,
+ and "operator" is a string containing the operator to use.
+ In order to specify a column name when a :class:`_schema.Column`
+ object is not available, while ensuring
that any necessary quoting rules take effect, an ad-hoc
:class:`_schema.Column` or :func:`_expression.column`
- object should be
- used.
+ object should be used. ``column`` may also be a string SQL
+ expression when passed as :func:`_expression.literal_column`
:param name:
Optional, the in-database name of this constraint.
tbl.append_constraint(cons)
self.assert_compile(
schema.AddConstraint(cons),
- "ALTER TABLE testtbl ADD EXCLUDE USING gist " "(room WITH =)",
+ "ALTER TABLE testtbl ADD EXCLUDE USING gist (room WITH =)",
dialect=postgresql.dialect(),
)
tbl.append_constraint(cons_copy)
self.assert_compile(
schema.AddConstraint(cons_copy),
- "ALTER TABLE testtbl ADD EXCLUDE USING gist " "(room WITH =)",
+ "ALTER TABLE testtbl ADD EXCLUDE USING gist (room WITH =)",
)
def test_exclude_constraint_copy_where_using(self):
dialect=postgresql.dialect(),
)
+ def test_exclude_constraint_literal_binds(self):
+ m = MetaData()
+ tbl = Table("foo", m, Column("x", Integer), Column("y", Integer))
+ cons = ExcludeConstraint(
+ (func.power(tbl.c.x, 42), "="),
+ (func.int8range(column("x"), "y"), "&&"),
+ )
+ tbl.append_constraint(cons)
+ self.assert_compile(
+ schema.AddConstraint(cons),
+ "ALTER TABLE foo ADD EXCLUDE USING gist "
+ "(power(x, 42) WITH =, int8range(x, 'y') WITH &&)",
+ dialect=postgresql.dialect(),
+ )
+
def test_substring(self):
self.assert_compile(
func.substring("abc", 1, 2),