From: jonathan vanasco Date: Thu, 23 Sep 2021 20:15:27 +0000 (-0400) Subject: Fixes: #3086 X-Git-Tag: rel_1_4_26~63 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=52e8545b2df312898d46f6a5b119675e8d0aa956;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fixes: #3086 show that `server_defaults` can accept contextually valid SQLAlchemy expressions or constructs Change-Id: I44c1a021a3e7ab7d66fea2d79a36cb2195a1969d --- diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 02c1b9cedb..a20ba0fbc2 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -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