diff options
| author | jonathan vanasco <jonathan@2xlp.com> | 2021-09-23 16:15:27 -0400 |
|---|---|---|
| committer | jonathan vanasco <jonathan@2xlp.com> | 2021-09-23 16:18:19 -0400 |
| commit | 52e8545b2df312898d46f6a5b119675e8d0aa956 (patch) | |
| tree | f2ed9d7b28a1ab67fff0c266ea75987584f10ffc /lib/sqlalchemy/sql | |
| parent | 7023c07aa6d31b3527cb1171410dcb6e8dff3ec3 (diff) | |
| download | sqlalchemy-52e8545b2df312898d46f6a5b119675e8d0aa956.tar.gz | |
Fixes: #3086
show that `server_defaults` can accept contextually valid SQLAlchemy expressions or constructs
Change-Id: I44c1a021a3e7ab7d66fea2d79a36cb2195a1969d
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/schema.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 02c1b9ced..a20ba0fbc 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 |
