summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_compiler.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2021-01-07 21:22:52 +0100
committerMike Bayer <mike_mp@zzzcomputing.com>2021-01-16 18:39:11 -0500
commit3ebc3710a72c9bb724e7074ef0409ae69cfc39fe (patch)
tree77f81978aa29869e516615998cb35ef1ce6dd115 /test/dialect/postgresql/test_compiler.py
parent6137d223be8e596fb2d7c78623ab22162db8ea6e (diff)
downloadsqlalchemy-3ebc3710a72c9bb724e7074ef0409ae69cfc39fe.tar.gz
``Identity`` implies ``nullable=False``.
Altered the behavior of the :class:`_schema.Identity` construct such that when applied to a :class:`_schema.Column`, it will automatically imply that the value of :paramref:`_sql.Column.nullable` should default to ``False``, in a similar manner as when the :paramref:`_sql.Column.primary_key` parameter is set to ``True``. This matches the default behavior of all supporting databases where ``IDENTITY`` implies ``NOT NULL``. The PostgreSQL backend is the only one that supports adding ``NULL`` to an ``IDENTITY`` column, which is here supported by passing a ``True`` value for the :paramref:`_sql.Column.nullable` parameter at the same time. Fixes: #5775 Change-Id: I0516d506ff327cff35cda605e8897a27440e0373
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r--test/dialect/postgresql/test_compiler.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py
index b3a0b9bbd..ec165960f 100644
--- a/test/dialect/postgresql/test_compiler.py
+++ b/test/dialect/postgresql/test_compiler.py
@@ -1778,6 +1778,25 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
"(INCREMENT BY 7 START WITH 4))",
)
+ def test_column_identity_null(self):
+ # all other tests are in test_identity_column.py
+ m = MetaData()
+ t = Table(
+ "t",
+ m,
+ Column(
+ "y",
+ Integer,
+ Identity(always=True, start=4, increment=7),
+ nullable=True,
+ ),
+ )
+ self.assert_compile(
+ schema.CreateTable(t),
+ "CREATE TABLE t (y INTEGER GENERATED ALWAYS AS IDENTITY "
+ "(INCREMENT BY 7 START WITH 4) NULL)",
+ )
+
def test_index_extra_include_1(self):
metadata = MetaData()
tbl = Table(