diff options
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r-- | test/dialect/postgresql/test_compiler.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 83e3ee3fd..4c4c43281 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 cast from sqlalchemy import Column +from sqlalchemy import Computed from sqlalchemy import delete from sqlalchemy import Enum from sqlalchemy import exc @@ -1541,6 +1542,42 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): q, "DELETE FROM t1 AS a1 USING t2 WHERE a1.c1 = t2.c1" ) + @testing.combinations( + ("no_persisted", " STORED", "ignore"), + ("persisted_none", " STORED", None), + ("persisted_true", " STORED", True), + id_="iaa", + ) + def test_column_computed(self, text, persisted): + m = MetaData() + kwargs = {"persisted": persisted} if persisted != "ignore" else {} + t = Table( + "t", + m, + Column("x", Integer), + Column("y", Integer, Computed("x + 2", **kwargs)), + ) + self.assert_compile( + schema.CreateTable(t), + "CREATE TABLE t (x INTEGER, y INTEGER GENERATED " + "ALWAYS AS (x + 2)%s)" % text, + ) + + def test_column_computed_persisted_false(self): + m = MetaData() + t = Table( + "t", + m, + Column("x", Integer), + Column("y", Integer, Computed("x + 2", persisted=False)), + ) + assert_raises_message( + exc.CompileError, + "PostrgreSQL computed columns do not support 'virtual'", + schema.CreateTable(t).compile, + dialect=postgresql.dialect(), + ) + class InsertOnConflictTest(fixtures.TestBase, AssertsCompiledSQL): __dialect__ = postgresql.dialect() |