class documentation

class Column(DialectKWArgs, SchemaItem, ColumnClause):

View In Hierarchy

Represents a column in a database table.
Method __init__ Construct a new Column object.
Method __repr__ Undocumented
Method __str__ Undocumented
Method ​_copy Create a copy of this Column, uninitialized.
Method ​_extra​_kwargs Undocumented
Method ​_make​_proxy Create a proxy for this column.
Method ​_on​_table​_attach Undocumented
Method ​_set​_parent Associate with this SchemaEvent's parent object.
Method ​_setup​_on​_memoized​_fks Undocumented
Method append​_foreign​_key Undocumented
Method copy Undocumented
Method references Return True if this Column references the given column via foreign key.
Class Variable __visit​_name__ Undocumented
Class Variable inherit​_cache Indicate if this .HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.
Instance Variable ​_proxies Undocumented
Instance Variable ​_user​_defined​_nullable Undocumented
Instance Variable autoincrement Undocumented
Instance Variable comment Undocumented
Instance Variable computed Undocumented
Instance Variable constraints Undocumented
Instance Variable default Undocumented
Instance Variable doc Undocumented
Instance Variable foreign​_keys A collection of all _schema.ForeignKey marker objects associated with this _schema.Column.
Instance Variable identity Undocumented
Instance Variable index The value of the :paramref:`_schema.Column.index` parameter.
Instance Variable info Info dictionary associated with the object, allowing user-defined data to be associated with this .SchemaItem.
Instance Variable key The 'key' that in some circumstances refers to this object in a Python namespace.
Instance Variable nullable Undocumented
Instance Variable onupdate Undocumented
Instance Variable primary​_key Undocumented
Instance Variable server​_default Undocumented
Instance Variable server​_onupdate Undocumented
Instance Variable system Undocumented
Instance Variable table Undocumented
Instance Variable unique The value of the :paramref:`_schema.Column.unique` parameter.

Inherited from DialectKWArgs:

Class Method argument​_for Add a new kind of dialect-specific keyword argument for this class.
Method ​_kw​_reg​_for​_dialect​_cls Undocumented
Method ​_validate​_dialect​_kwargs Undocumented
Class Variable ​_dialect​_kwargs​_traverse​_internals Undocumented
Class Variable ​_kw​_registry Undocumented
Property dialect​_kwargs A collection of keyword arguments specified as dialect-specific options to this construct.
Property dialect​_options A collection of keyword arguments specified as dialect-specific options to this construct.
Property kwargs A synonym for .DialectKWArgs.dialect_kwargs.

Inherited from SchemaItem:

Method ​_init​_items Initialize the list of child items for this SchemaItem.
Method ​_schema​_item​_copy Undocumented
Class Variable ​_use​_schema​_map Undocumented
Class Variable create​_drop​_stringify​_dialect Undocumented

Inherited from SchemaEventTarget (via SchemaItem):

Method ​_set​_parent​_with​_dispatch Undocumented

Inherited from Traversible (via SchemaItem):

Method get​_children Return immediate child .visitors.Traversible elements of this .visitors.Traversible.
Method __class​_getitem__ Undocumented

Inherited from ColumnClause:

Method ​_clone Create a shallow copy of this ClauseElement.
Method ​_compare​_name​_for​_result Return True if the given column element compares to this one when targeting within a result row.
Method ​_from​_objects Undocumented
Method ​_gen​_tq​_label generate table-qualified label
Method ​_render​_label​_in​_columns​_clause No summary
Method get​_children Return immediate child .visitors.Traversible elements of this .visitors.Traversible.
Class Variable ​_is​_multiparam​_column Undocumented
Class Variable ​_traverse​_internals Undocumented
Instance Variable is​_literal Undocumented
Instance Variable name Undocumented
Instance Variable type Undocumented
Property ​_ddl​_label Undocumented
Property entity​_namespace Undocumented

Inherited from DDLReferredColumnRole (via ColumnClause):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via ColumnClause, DDLReferredColumnRole, DDLConstraintColumnRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from ExpressionElementRole (via ColumnClause, LabeledColumnExprRole):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via ColumnClause, LabeledColumnExprRole, ExpressionElementRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from StrAsPlainColumnRole (via ColumnClause):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via ColumnClause, StrAsPlainColumnRole, ColumnArgumentRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from Immutable (via ColumnClause):

Method ​_copy​_internals Undocumented
Method params Undocumented
Method unique​_params Undocumented
Class Variable ​_is​_immutable Undocumented

Inherited from NamedColumn (via ColumnClause):

Method ​_bind​_param Undocumented
Method ​_non​_anon​_label the 'name' that naturally applies this element when rendered in SQL.
Method ​_tq​_key​_label table qualified label based on column key.
Method ​_tq​_label table qualified label based on column name.
Property description Undocumented

Inherited from ColumnElement (via ColumnClause, NamedColumn):

Method cast Produce a type cast, i.e. CAST(<expression> AS <type>).
Method label Produce a column label, i.e. <columnname> AS <name>.
Method operate Operate on an argument.
Method reverse​_operate Reverse operate on an argument.
Method self​_group Apply a 'grouping' to this _expression.ClauseElement.
Method shares​_lineage Return True if the given _expression.ColumnElement has a common ancestor to this _expression.ColumnElement.
Method __getattr__ Undocumented
Method ​_anon​_label Undocumented
Method ​_dedupe​_anon​_label​_idx label to apply to a column that is anon labeled, but repeated in the SELECT, so that we have to make an "extra anon" label that disambiguates it from the previous appearance.
Method ​_dedupe​_anon​_tq​_label​_idx Undocumented
Method ​_expression​_label a suggested label to use in the case that the column has no name, which should be used if possible as the explicit 'AS <label>' where this expression would normally have an anon label.
Method ​_negate Undocumented
Method ​_proxy​_key Undocumented
Method ​_uncached​_proxy​_set An 'uncached' version of proxy set.
Method comparator Undocumented
Class Variable ​_allow​_label​_resolve A flag that can be flipped to prevent a column from being resolvable by string label name.
Class Variable ​_alt​_names Undocumented
Class Variable ​_is​_implicitly​_boolean Undocumented
Property ​_anon​_key​_label Provides a constant 'anonymous key label' for this ColumnElement.
Property ​_anon​_name​_label Provides a constant 'anonymous label' for this ColumnElement.
Property ​_anon​_tq​_key​_label Undocumented
Property ​_anon​_tq​_label Undocumented
Property ​_key​_label legacy; renamed to _tq_key_label
Property ​_label legacy; renamed to _tq_label
Property ​_select​_iterable Undocumented
Property anon​_key​_label Undocumented
Property anon​_label Undocumented
Property base​_columns Undocumented
Property expression Return a column expression.
Property proxy​_set Undocumented

Inherited from ColumnArgumentOrKeyRole (via ColumnClause, NamedColumn, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via ColumnClause, NamedColumn, ColumnElement, ColumnArgumentOrKeyRole, ColumnArgumentRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from StatementOptionRole (via ColumnClause, NamedColumn, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via ColumnClause, NamedColumn, ColumnElement, StatementOptionRole, StructuralRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from WhereHavingRole (via ColumnClause, NamedColumn, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from AllowsLambdaRole (via ColumnClause, NamedColumn, ColumnElement, WhereHavingRole, OnClauseRole):

Class Variable allows​_lambda Undocumented

Inherited from SQLRole (via ColumnClause, NamedColumn, ColumnElement, WhereHavingRole, OnClauseRole, StructuralRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from BinaryElementRole (via ColumnClause, NamedColumn, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via ColumnClause, NamedColumn, ColumnElement, BinaryElementRole, ExpressionElementRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from OrderByRole (via ColumnClause, NamedColumn, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from AllowsLambdaRole (via ColumnClause, NamedColumn, ColumnElement, OrderByRole):

Class Variable allows​_lambda Undocumented

Inherited from SQLRole (via ColumnClause, NamedColumn, ColumnElement, OrderByRole, ByOfRole, ColumnListRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from ColumnsClauseRole (via ColumnClause, NamedColumn, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from AllowsLambdaRole (via ColumnClause, NamedColumn, ColumnElement, ColumnsClauseRole):

Class Variable allows​_lambda Undocumented

Inherited from UsesInspection (via ColumnClause, NamedColumn, ColumnElement, ColumnsClauseRole):

Class Variable ​_post​_inspect Undocumented
Class Variable uses​_inspection Undocumented

Inherited from SQLRole (via ColumnClause, NamedColumn, ColumnElement, ColumnsClauseRole, ColumnListRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from LimitOffsetRole (via ColumnClause, NamedColumn, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via ColumnClause, NamedColumn, ColumnElement, LimitOffsetRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from DMLColumnRole (via ColumnClause, NamedColumn, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via ColumnClause, NamedColumn, ColumnElement, DMLColumnRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from DDLConstraintColumnRole (via ColumnClause, NamedColumn, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via ColumnClause, NamedColumn, ColumnElement, DDLConstraintColumnRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from DDLExpressionRole (via ColumnClause, NamedColumn, ColumnElement):

Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via ColumnClause, NamedColumn, ColumnElement, DDLExpressionRole, StructuralRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from ColumnOperators (via ColumnClause, NamedColumn, ColumnElement):

Method __add__ Implement the + operator.
Method __contains__ Undocumented
Method __div__ Implement the / operator.
Method __eq__ Implement the == operator.
Method __ge__ Implement the >= operator.
Method __getitem__ Implement the [] operator.
Method __gt__ Implement the > operator.
Method __le__ Implement the <= operator.
Method __lshift__ implement the << operator.
Method __lt__ Implement the < operator.
Method __mod__ Implement the % operator.
Method __mul__ Implement the * operator.
Method __ne__ Implement the != operator.
Method __neg__ Implement the - operator.
Method __radd__ Implement the + operator in reverse.
Method __rdiv__ Implement the / operator in reverse.
Method __rmod__ Implement the % operator in reverse.
Method __rmul__ Implement the * operator in reverse.
Method __rshift__ implement the >> operator.
Method __rsub__ Implement the - operator in reverse.
Method __rtruediv__ Implement the // operator in reverse.
Method __sub__ Implement the - operator.
Method __truediv__ Implement the // operator.
Method all​_ Produce an _expression.all_ clause against the parent object.
Method any​_ Produce an _expression.any_ clause against the parent object.
Method asc Produce a _expression.asc clause against the parent object.
Method between Produce a _expression.between clause against the parent object, given the lower and upper range.
Method collate Produce a _expression.collate clause against the parent object, given the collation string.
Method concat Implement the 'concat' operator.
Method contains Implement the 'contains' operator.
Method desc Produce a _expression.desc clause against the parent object.
Method distinct Produce a _expression.distinct clause against the parent object.
Method endswith Implement the 'endswith' operator.
Method ilike Implement the ilike operator, e.g. case insensitive LIKE.
Method in​_ Implement the in operator.
Method is​_ Implement the IS operator.
Method is​_distinct​_from Implement the IS DISTINCT FROM operator.
Method is​_not Implement the IS NOT operator.
Method is​_not​_distinct​_from Implement the IS NOT DISTINCT FROM operator.
Method like Implement the like operator.
Method match Implements a database-specific 'match' operator.
Method not​_ilike implement the NOT ILIKE operator.
Method not​_in implement the NOT IN operator.
Method not​_like implement the NOT LIKE operator.
Method nulls​_first Produce a _expression.nulls_first clause against the parent object.
Method nulls​_last Produce a _expression.nulls_last clause against the parent object.
Method regexp​_match Implements a database-specific 'regexp match' operator.
Method regexp​_replace Implements a database-specific 'regexp replace' operator.
Method startswith Implement the startswith operator.
Class Variable __slots__ Undocumented
Class Variable timetuple Hack, allows datetime objects to be compared on the LHS.

Inherited from Operators (via ColumnClause, NamedColumn, ColumnElement, ColumnOperators):

Method __and__ Implement the & operator.
Method __invert__ Implement the ~ operator.
Method __or__ Implement the | operator.
Method bool​_op Return a custom boolean operator.
Method op Produce a generic operator function.

Inherited from ClauseElement (via ColumnClause, NamedColumn, ColumnElement):

Method compare Compare this _expression.ClauseElement to the given _expression.ClauseElement.
Method compile Compile this SQL expression.
Method params Return a copy with _expression.bindparam elements replaced.
Method unique​_params Return a copy with _expression.bindparam elements replaced.
Method __bool__ Undocumented
Method __getstate__ Undocumented
Method __invert__ Undocumented
Method ​_cloned​_set Return the set consisting all cloned ancestors of this ClauseElement.
Method ​_compile​_w​_cache Undocumented
Method ​_compiler Return a compiler appropriate for this ClauseElement, given a Dialect.
Method ​_execute​_on​_connection Undocumented
Method ​_negate​_in​_binary a hook to allow the right side of a binary expression to respond to a negation of the binary expression.
Method ​_replace​_params Undocumented
Method ​_set​_propagate​_attrs Undocumented
Method ​_ungroup Return this _expression.ClauseElement without any groupings.
Method ​_with​_binary​_element​_type in the context of binary expression, convert the type of this object to the one given.
Class Variable ​_cache​_key​_traversal Undocumented
Class Variable ​_is​_bind​_parameter Undocumented
Class Variable ​_is​_clause​_list Undocumented
Class Variable ​_is​_clone​_of Undocumented
Class Variable ​_is​_from​_clause Undocumented
Class Variable ​_is​_from​_container Undocumented
Class Variable ​_is​_immutable Undocumented
Class Variable ​_is​_lambda​_element Undocumented
Class Variable ​_is​_returns​_rows Undocumented
Class Variable ​_is​_select​_container Undocumented
Class Variable ​_is​_select​_statement Undocumented
Class Variable ​_is​_singleton​_constant Undocumented
Class Variable ​_is​_text​_clause Undocumented
Class Variable ​_is​_textual Undocumented
Class Variable ​_order​_by​_label​_element Undocumented
Class Variable bind Undocumented
Class Variable is​_clause​_element Undocumented
Class Variable is​_selectable Undocumented
Class Variable stringify​_dialect Undocumented
Class Variable supports​_execution Undocumented
Instance Variable ​_propagate​_attrs like annotations, however these propagate outwards liberally as SQL constructs are built, and are set up at construction time.
Property ​_constructor return the 'constructor' for this ClauseElement.

Inherited from SQLRole (via ColumnClause, NamedColumn, ColumnElement, ClauseElement):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from SupportsWrappingAnnotations (via ColumnClause, NamedColumn, ColumnElement, ClauseElement):

Method ​_annotate return a copy of this ClauseElement with annotations updated by the given dictionary.
Method ​_deannotate return a copy of this _expression.ClauseElement with annotations removed.
Method ​_with​_annotations return a copy of this ClauseElement with annotations replaced by the given dictionary.

Inherited from SupportsAnnotations (via ColumnClause, NamedColumn, ColumnElement, ClauseElement, SupportsWrappingAnnotations):

Property ​_annotations​_cache​_key Undocumented

Inherited from MemoizedHasCacheKey (via ColumnClause, NamedColumn, ColumnElement, ClauseElement):

Method ​_generate​_cache​_key return a cache key.

Inherited from HasCacheKey (via ColumnClause, NamedColumn, ColumnElement, ClauseElement, MemoizedHasCacheKey):

Class Method ​_generate​_cache​_attrs generate cache key dispatcher for a new class.
Class Method ​_generate​_cache​_key​_for​_object Undocumented
Method ​_gen​_cache​_key return an optional cache key.
Class Variable __slots__ Undocumented
Class Variable ​_hierarchy​_supports​_caching private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses.
Class Variable ​_is​_has​_cache​_key Undocumented

Inherited from HasCopyInternals (via ColumnClause, NamedColumn, ColumnElement, ClauseElement):

Method ​_copy​_internals Reassign internal elements to be clones of themselves.

Inherited from Traversible (via ColumnClause, NamedColumn, ColumnElement, ClauseElement):

Method __class​_getitem__ Undocumented
def __init__(self, *args, **kwargs):
Construct a new Column object.
Parameters
*argsAdditional positional arguments include various .SchemaItem derived constructs which will be applied as options to the column. These include instances of .Constraint, _schema.ForeignKey, .ColumnDefault, .Sequence, .Computed .Identity. In some cases an equivalent keyword argument is available such as server_default, default and unique.
**kwargsUndocumented
name

The name of this column as represented in the database. This argument may be the first positional argument, or specified via keyword.

Names which contain no upper case characters will be treated as case insensitive names, and will not be quoted unless they are a reserved word. Names with any number of upper case characters will be quoted and sent exactly. Note that this behavior applies even for databases which standardize upper case names as case insensitive such as Oracle.

The name field may be omitted at construction time and applied later, at any time before the Column is associated with a _schema.Table. This is to support convenient usage within the ~sqlalchemy.ext.declarative extension.

type​_

The column's type, indicated using an instance which subclasses ~sqlalchemy.types.TypeEngine. If no arguments are required for the type, the class of the type can be sent as well, e.g.:

# use a type with arguments
Column('data', String(50))

# use no arguments
Column('level', Integer)

The type argument may be the second positional argument or specified by keyword.

If the type is None or is omitted, it will first default to the special type .NullType. If and when this _schema.Column is made to refer to another column using _schema.ForeignKey and/or _schema.ForeignKeyConstraint, the type of the remote-referenced column will be copied to this column as well, at the moment that the foreign key is resolved against that remote _schema.Column object.

Changed in version 0.9.0: Support for propagation of type to a _schema.Column from its _schema.ForeignKey object has been improved and should be more reliable and timely.
autoincrement

Set up "auto increment" semantics for an integer primary key column. The default value is the string "auto" which indicates that a single-column primary key that is of an INTEGER type with no stated client-side or python-side defaults should receive auto increment semantics automatically; all other varieties of primary key columns will not. This includes that :term:`DDL` such as PostgreSQL SERIAL or MySQL AUTO_INCREMENT will be emitted for this column during a table create, as well as that the column is assumed to generate new integer primary key values when an INSERT statement invokes which will be retrieved by the dialect. When used in conjunction with .Identity on a dialect that supports it, this parameter has no effect.

The flag may be set to True to indicate that a column which is part of a composite (e.g. multi-column) primary key should have autoincrement semantics, though note that only one column within a primary key may have this setting. It can also be set to True to indicate autoincrement semantics on a column that has a client-side or server-side default configured, however note that not all dialects can accommodate all styles of default as an "autoincrement". It can also be set to False on a single-column primary key that has a datatype of INTEGER in order to disable auto increment semantics for that column.

Changed in version 1.1: The autoincrement flag now defaults to "auto" which indicates autoincrement semantics by default for single-column integer primary keys only; for composite (multi-column) primary keys, autoincrement is never implicitly enabled; as always, autoincrement=True will allow for at most one of those columns to be an "autoincrement" column. autoincrement=True may also be set on a _schema.Column that has an explicit client-side or server-side default, subject to limitations of the backend database and dialect.

The setting only has an effect for columns which are:

  • Integer derived (i.e. INT, SMALLINT, BIGINT).

  • Part of the primary key

  • Not referring to another column via _schema.ForeignKey, unless the value is specified as 'ignore_fk':

    # turn on autoincrement for this column despite
    # the ForeignKey()
    Column('id', ForeignKey('other.id'),
                primary_key=True, autoincrement='ignore_fk')
    

    It is typically not desirable to have "autoincrement" enabled on a column that refers to another via foreign key, as such a column is required to refer to a value that originates from elsewhere.

The setting has these two effects on columns that meet the above criteria:

  • DDL issued for the column will include database-specific keywords intended to signify this column as an "autoincrement" column, such as AUTO INCREMENT on MySQL, SERIAL on PostgreSQL, and IDENTITY on MS-SQL. It does not issue AUTOINCREMENT for SQLite since this is a special SQLite flag that is not required for autoincrementing behavior.

  • The column will be considered to be available using an "autoincrement" method specific to the backend database, such as calling upon cursor.lastrowid, using RETURNING in an INSERT statement to get at a sequence-generated value, or using special functions such as "SELECT scope_identity()". These methods are highly specific to the DBAPIs and databases in use and vary greatly, so care should be taken when associating autoincrement=True with a custom default generation function.

default

A scalar, Python callable, or _expression.ColumnElement expression representing the default value for this column, which will be invoked upon insert if this column is otherwise not specified in the VALUES clause of the insert. This is a shortcut to using .ColumnDefault as a positional argument; see that class for full detail on the structure of the argument.

Contrast this argument to :paramref:`_schema.Column.server_default` which creates a default generator on the database side.

docoptional String that can be used by the ORM or similar to document attributes on the Python side. This attribute does not render SQL comments; use the :paramref:`_schema.Column.comment` parameter for this purpose.
keyAn optional string identifier which will identify this Column object on the _schema.Table. When a key is provided, this is the only identifier referencing the Column within the application, including ORM attribute mapping; the name field is used only when rendering SQL.
index

When True, indicates that a _schema.Index construct will be automatically generated for this _schema.Column, which will result in a "CREATE INDEX" statement being emitted for the _schema.Table when the DDL create operation is invoked.

Using this flag is equivalent to making use of the _schema.Index construct explicitly at the level of the _schema.Table construct itself:

Table(
    "some_table",
    metadata,
    Column("x", Integer),
    Index("ix_some_table_x", "x")
)

To add the :paramref:`_schema.Index.unique` flag to the _schema.Index, set both the :paramref:`_schema.Column.unique` and :paramref:`_schema.Column.index` flags to True simultaneously, which will have the effect of rendering the "CREATE UNIQUE INDEX" DDL instruction instead of "CREATE INDEX".

The name of the index is generated using the :ref:`default naming convention <constraint_default_naming_convention>` which for the _schema.Index construct is of the form ix_<tablename>_<columnname>.

As this flag is intended only as a convenience for the common case of adding a single-column, default configured index to a table definition, explicit use of the _schema.Index construct should be preferred for most use cases, including composite indexes that encompass more than one column, indexes with SQL expressions or ordering, backend-specific index configuration options, and indexes that use a specific name.

Note

the _schema.Column.index attribute on _schema.Column does not indicate if this column is indexed or not, only if this flag was explicitly set here. To view indexes on a column, view the _schema.Table.indexes collection or use _reflection.Inspector.get_indexes.

infoOptional data dictionary which will be populated into the .SchemaItem.info attribute of this object.
nullable

When set to False, will cause the "NOT NULL" phrase to be added when generating DDL for the column. When True, will normally generate nothing (in SQL this defaults to "NULL"), except in some very specific backend-specific edge cases where "NULL" may render explicitly. Defaults to True unless :paramref:`_schema.Column.primary_key` is also True or the column specifies a _sql.Identity, in which case it defaults to False. This parameter is only used when issuing CREATE TABLE statements.

Note

When the column specifies a _sql.Identity this parameter is in general ignored by the DDL compiler. The PostgreSQL database allows nullable identity column by setting this parameter to True explicitly.

onupdate

A scalar, Python callable, or ~sqlalchemy.sql.expression.ClauseElement representing a default value to be applied to the column within UPDATE statements, which will be invoked upon update if this column is not present in the SET clause of the update. This is a shortcut to using .ColumnDefault as a positional argument with for_update=True.

See Also

:ref:`metadata_defaults` - complete discussion of onupdate

primary​_keyIf True, marks this column as a primary key column. Multiple columns can have this flag set to specify composite primary keys. As an alternative, the primary key of a _schema.Table can be specified via an explicit .PrimaryKeyConstraint object.
server​_default

A .FetchedValue instance, str, Unicode or ~sqlalchemy.sql.expression.text construct representing the DDL DEFAULT value for the column.

String types will be emitted as-is, surrounded by single quotes:

Column('x', Text, server_default="val")

x TEXT DEFAULT 'val'

A ~sqlalchemy.sql.expression.text expression will be rendered as-is, without quotes:

Column('y', DateTime, server_default=text('NOW()'))

y DATETIME DEFAULT NOW()

Strings and text() will be converted into a .DefaultClause object upon initialization.

This parameter can also accept complex combinations 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 .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 construct does not specify any DDL and the implementation is left to the database, such as via a trigger.

See Also

:ref:`server_defaults` - complete discussion of server side defaults

server​_onupdate

A .FetchedValue instance representing a database-side default generation function, such as a trigger. This indicates to SQLAlchemy that a newly generated value will be available after updates. This construct does not actually implement any kind of generation function within the database, which instead must be specified separately.

Warning

This directive does not currently produce MySQL's "ON UPDATE CURRENT_TIMESTAMP()" clause. See :ref:`mysql_timestamp_onupdate` for background on how to produce this clause.

quoteForce quoting of this column's name on or off, corresponding to True or False. When left at its default of None, the column identifier will be quoted according to whether the name is case sensitive (identifiers with at least one upper case character are treated as case sensitive), or if it's a reserved word. This flag is only needed to force quoting of a reserved word which is not known by the SQLAlchemy dialect.
unique

When True, and the :paramref:`_schema.Column.index` parameter is left at its default value of False, indicates that a _schema.UniqueConstraint construct will be automatically generated for this _schema.Column, which will result in a "UNIQUE CONSTRAINT" clause referring to this column being included in the CREATE TABLE statement emitted, when the DDL create operation for the _schema.Table object is invoked.

When this flag is True while the :paramref:`_schema.Column.index` parameter is simultaneously set to True, the effect instead is that a _schema.Index construct which includes the :paramref:`_schema.Index.unique` parameter set to True is generated. See the documentation for :paramref:`_schema.Column.index` for additional detail.

Using this flag is equivalent to making use of the _schema.UniqueConstraint construct explicitly at the level of the _schema.Table construct itself:

Table(
    "some_table",
    metadata,
    Column("x", Integer),
    UniqueConstraint("x")
)

The :paramref:`_schema.UniqueConstraint.name` parameter of the unique constraint object is left at its default value of None; in the absence of a :ref:`naming convention <constraint_naming_conventions>` for the enclosing _schema.MetaData, the UNIQUE CONSTRAINT construct will be emitted as unnamed, which typically invokes a database-specific naming convention to take place.

As this flag is intended only as a convenience for the common case of adding a single-column, default configured unique constraint to a table definition, explicit use of the _schema.UniqueConstraint construct should be preferred for most use cases, including composite constraints that encompass more than one column, backend-specific index configuration options, and constraints that use a specific name.

Note

the _schema.Column.unique attribute on _schema.Column does not indicate if this column has a unique constraint or not, only if this flag was explicitly set here. To view indexes and unique constraints that may involve this column, view the _schema.Table.indexes and/or _schema.Table.constraints collections or use _reflection.Inspector.get_indexes and/or _reflection.Inspector.get_unique_constraints

system

When True, indicates this is a "system" column, that is a column which is automatically made available by the database, and should not be included in the columns list for a CREATE TABLE statement.

For more elaborate scenarios where columns should be conditionally rendered differently on different backends, consider custom compilation rules for .CreateColumn.

comment

Optional string that will render an SQL comment on table creation.

New in version 1.2: Added the :paramref:`_schema.Column.comment` parameter to _schema.Column.
def __repr__(self):
def __str__(self):
def _copy(self, **kw):

Create a copy of this Column, uninitialized.

This is used in _schema.Table.to_metadata.

def _extra_kwargs(self, **kwargs):

Undocumented

def _make_proxy(self, selectable, name=None, key=None, name_is_truncatable=False, **kw):

Create a proxy for this column.

This is a copy of this Column referenced by a different parent (such as an alias or select statement). The column should be used only in select scenarios, as its full DDL/default information is not transferred.

def _on_table_attach(self, fn):

Undocumented

def _set_parent(self, table, allow_replacements=True):
Associate with this SchemaEvent's parent object.
def _setup_on_memoized_fks(self, fn):

Undocumented

def append_foreign_key(self, fk):

Undocumented

@util.deprecated('1.4', 'The :meth:`_schema.Column.copy` method is deprecated and will be removed in a future release.')
def copy(self, **kw):

Undocumented

def references(self, column):
Return True if this Column references the given column via foreign key.
__visit_name__: str =
inherit_cache: bool =

Indicate if this .HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.

The attribute defaults to None, which indicates that a construct has not yet taken into account whether or not its appropriate for it to participate in caching; this is functionally equivalent to setting the value to False, except that a warning is also emitted.

This flag can be set to True on a particular class, if the SQL that corresponds to the object does not change based on attributes which are local to this class, and not its superclass.

See Also

:ref:`compilerext_caching` - General guideslines for setting the .HasCacheKey.inherit_cache attribute for third-party or user defined SQL constructs.

_proxies =
_user_defined_nullable =

Undocumented

autoincrement =

Undocumented

comment =

Undocumented

computed =

Undocumented

constraints: set =

Undocumented

default =
doc =

Undocumented

foreign_keys =

A collection of all _schema.ForeignKey marker objects associated with this _schema.Column.

Each object is a member of a _schema.Table-wide _schema.ForeignKeyConstraint.

See Also

_schema.Table.foreign_keys

identity =

Undocumented

index =

The value of the :paramref:`_schema.Column.index` parameter.

Does not indicate if this _schema.Column is actually indexed or not; use _schema.Table.indexes.

See Also

_schema.Table.indexes

info =

Info dictionary associated with the object, allowing user-defined data to be associated with this .SchemaItem.

The dictionary is automatically generated when first accessed. It can also be specified in the constructor of some objects, such as _schema.Table and _schema.Column.

key =

The 'key' that in some circumstances refers to this object in a Python namespace.

This typically refers to the "key" of the column as present in the .c collection of a selectable, e.g. sometable.c["somekey"] would return a _schema.Column with a .key of "somekey".

nullable =

Undocumented

onupdate =
primary_key =
server_default =
server_onupdate =
system =

Undocumented

table =
unique =

The value of the :paramref:`_schema.Column.unique` parameter.

Does not indicate if this _schema.Column is actually subject to a unique constraint or not; use _schema.Table.indexes and _schema.Table.constraints.

See Also

_schema.Table.indexes

_schema.Table.constraints.