diff options
author | Federico Caselli <cfederico87@gmail.com> | 2023-03-01 23:22:46 +0100 |
---|---|---|
committer | Federico Caselli <cfederico87@gmail.com> | 2023-03-01 23:22:46 +0100 |
commit | 7099dd20e90307237240f30d5db0816a08356a5b (patch) | |
tree | d65c0091726daffcf91ca27f9afa79819044090d /test/dialect/postgresql/test_compiler.py | |
parent | 9d9e47fe9398b6bcda917f63441d2b5ad4b345c4 (diff) | |
download | sqlalchemy-7099dd20e90307237240f30d5db0816a08356a5b.tar.gz |
Fixed issue when copying ExcludeConstraint
Fixes: #9401
Change-Id: Ie10192348749567110f53ae618fc724f37d1a6a1
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r-- | test/dialect/postgresql/test_compiler.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 2c0dbfccd..25b02ade9 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -1135,6 +1135,40 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): "ALTER TABLE testtbl ADD EXCLUDE USING gist (room WITH =)", ) + def test_exclude_constraint_copy_complex(self): + m = MetaData() + tbl = Table("foo", m, Column("x", Integer), Column("y", Integer)) + cons = ExcludeConstraint( + (tbl.c.x, "*"), + (text("x-y"), "%"), + (literal_column("x+y"), "$"), + (tbl.c.x // tbl.c.y, "??"), + (func.power(tbl.c.x, 42), "="), + (func.int8range(column("x"), column("y")), "&&"), + ("y", "^"), + ) + tbl.append_constraint(cons) + expected = ( + "ALTER TABLE {name} ADD EXCLUDE USING gist " + "(x WITH *, x-y WITH %, x+y WITH $, x / y WITH ??, " + "power(x, 42) WITH =, int8range(x, y) WITH &&, y WITH ^)" + ) + self.assert_compile( + schema.AddConstraint(cons), + expected.format(name="foo"), + dialect=postgresql.dialect(), + ) + m2 = MetaData() + tbl2 = tbl.to_metadata(m2, name="bar") + (cons2,) = [ + c for c in tbl2.constraints if isinstance(c, ExcludeConstraint) + ] + self.assert_compile( + schema.AddConstraint(cons2), + expected.format(name="bar"), + dialect=postgresql.dialect(), + ) + def test_exclude_constraint_copy_where_using(self): m = MetaData() tbl = Table("testtbl", m, Column("room", Integer, primary_key=True)) |