summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_compiler.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r--test/dialect/postgresql/test_compiler.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py
index 0e04ccb95..b98d0fac6 100644
--- a/test/dialect/postgresql/test_compiler.py
+++ b/test/dialect/postgresql/test_compiler.py
@@ -3,6 +3,7 @@ from sqlalchemy import and_
from sqlalchemy import BigInteger
from sqlalchemy import bindparam
from sqlalchemy import cast
+from sqlalchemy import CheckConstraint
from sqlalchemy import Column
from sqlalchemy import Computed
from sqlalchemy import Date
@@ -10,6 +11,8 @@ from sqlalchemy import delete
from sqlalchemy import Enum
from sqlalchemy import exc
from sqlalchemy import Float
+from sqlalchemy import ForeignKey
+from sqlalchemy import ForeignKeyConstraint
from sqlalchemy import func
from sqlalchemy import Identity
from sqlalchemy import Index
@@ -828,6 +831,62 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
schema.DropIndex(idx1), "DROP INDEX test_idx1", dialect=dialect_9_1
)
+ def test_create_check_constraint_not_valid(self):
+ m = MetaData()
+
+ tbl = Table(
+ "testtbl",
+ m,
+ Column("data", Integer),
+ CheckConstraint("data = 0", postgresql_not_valid=True),
+ )
+
+ self.assert_compile(
+ schema.CreateTable(tbl),
+ "CREATE TABLE testtbl (data INTEGER, CHECK (data = 0) NOT VALID)",
+ )
+
+ def test_create_foreign_key_constraint_not_valid(self):
+ m = MetaData()
+
+ tbl = Table(
+ "testtbl",
+ m,
+ Column("a", Integer),
+ Column("b", Integer),
+ ForeignKeyConstraint(
+ "b", ["testtbl.a"], postgresql_not_valid=True
+ ),
+ )
+
+ self.assert_compile(
+ schema.CreateTable(tbl),
+ "CREATE TABLE testtbl ("
+ "a INTEGER, "
+ "b INTEGER, "
+ "FOREIGN KEY(b) REFERENCES testtbl (a) NOT VALID"
+ ")",
+ )
+
+ def test_create_foreign_key_column_not_valid(self):
+ m = MetaData()
+
+ tbl = Table(
+ "testtbl",
+ m,
+ Column("a", Integer),
+ Column("b", ForeignKey("testtbl.a", postgresql_not_valid=True)),
+ )
+
+ self.assert_compile(
+ schema.CreateTable(tbl),
+ "CREATE TABLE testtbl ("
+ "a INTEGER, "
+ "b INTEGER, "
+ "FOREIGN KEY(b) REFERENCES testtbl (a) NOT VALID"
+ ")",
+ )
+
def test_exclude_constraint_min(self):
m = MetaData()
tbl = Table("testtbl", m, Column("room", Integer, primary_key=True))