]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixes: #3086
authorjonathan vanasco <jonathan@2xlp.com>
Thu, 23 Sep 2021 20:15:27 +0000 (16:15 -0400)
committerjonathan vanasco <jonathan@2xlp.com>
Thu, 23 Sep 2021 20:18:19 +0000 (16:18 -0400)
show that `server_defaults` can accept contextually valid SQLAlchemy expressions or constructs

Change-Id: I44c1a021a3e7ab7d66fea2d79a36cb2195a1969d

lib/sqlalchemy/sql/schema.py

index 02c1b9cedb18bd94aed4d7c1b1c97c53264e2160..a20ba0fbc23bdc3859ab39893872d1c872c61843 100644 (file)
@@ -1423,6 +1423,33 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
             Strings and text() will be converted into a
             :class:`.DefaultClause` object upon initialization.
 
+            This parameter can also accept complex compbinations of contextually
+            valid SQLAlchemy expressions or constructs::
+
+                from sqlalchemy import create_engine
+                from sqlalchemy import Table, Column, MetaData, ARRAY, Text
+                from sqlalchemy.dialects.postgresql import array
+
+                engine = create_engine(
+                    'postgresql://scott:tiger@localhost/mydatabase'
+                )
+                metadata_obj = MetaData()
+                tbl = Table(
+                        "foo",
+                        metadata_obj,
+                        Column("bar",
+                               ARRAY(Text),
+                               server_default=array(["biz", "bang", "bash"])
+                               )
+                )
+                metadata_obj.create_all(engine)
+
+            The above results in a table created with the following SQL::
+
+                CREATE TABLE foo (
+                    bar TEXT[] DEFAULT ARRAY['biz', 'bang', 'bash']
+                )
+
             Use :class:`.FetchedValue` to indicate that an already-existing
             column will generate a default value on the database side which
             will be available to SQLAlchemy for post-fetch after inserts. This