diff options
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 |
