class documentation

class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem):

View In Hierarchy

A table-level INDEX.

Defines a composite (one or more column) INDEX.

E.g.:

sometable = Table("sometable", metadata,
                Column("name", String(50)),
                Column("address", String(100))
            )

Index("some_index", sometable.c.name)

For a no-frills, single column index, adding _schema.Column also supports index=True:

sometable = Table("sometable", metadata,
                Column("name", String(50), index=True)
            )

For a composite index, multiple columns can be specified:

Index("some_index", sometable.c.name, sometable.c.address)

Functional indexes are supported as well, typically by using the .func construct in conjunction with table-bound _schema.Column objects:

Index("some_index", func.lower(sometable.c.name))

An .Index can also be manually associated with a _schema.Table, either through inline declaration or using _schema.Table.append_constraint. When this approach is used, the names of the indexed columns can be specified as strings:

Table("sometable", metadata,
                Column("name", String(50)),
                Column("address", String(100)),
                Index("some_index", "name", "address")
        )

To support functional or expression-based indexes in this form, the _expression.text construct may be used:

from sqlalchemy import text

Table("sometable", metadata,
                Column("name", String(50)),
                Column("address", String(100)),
                Index("some_index", text("lower(name)"))
        )
New in version 0.9.5: the _expression.text construct may be used to specify .Index expressions, provided the .Index is explicitly associated with the _schema.Table.

See Also

:ref:`schema_indexes` - General information on .Index.

:ref:`postgresql_indexes` - PostgreSQL-specific options available for the .Index construct.

:ref:`mysql_indexes` - MySQL-specific options available for the .Index construct.

:ref:`mssql_indexes` - MSSQL-specific options available for the .Index construct.

Method __init__ Construct an index object.
Method __repr__ Undocumented
Method ​_set​_parent Associate with this SchemaEvent's parent object.
Method create Issue a CREATE statement for this .Index, using the given .Connectable for connectivity.
Method drop Issue a DROP statement for this .Index, using the given .Connectable for connectivity.
Class Variable __visit​_name__ Undocumented
Instance Variable expressions Undocumented
Instance Variable info Info dictionary associated with the object, allowing user-defined data to be associated with this .SchemaItem.
Instance Variable name Undocumented
Instance Variable table Undocumented
Instance Variable unique Undocumented
Property bind Return the connectable associated with this Index.

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 ColumnCollectionMixin:

Method ​_check​_attach Undocumented
Method ​_col​_expressions Undocumented
Class Variable ​_allow​_multiple​_tables Undocumented
Instance Variable ​_cols​_wo​_table Undocumented
Instance Variable ​_column​_flag Undocumented
Instance Variable ​_pending​_colargs Undocumented
Instance Variable columns A _expression.ColumnCollection of _schema.Column objects.

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
def __init__(self, name, *expressions, **kw):
Construct an index object.
Parameters
nameThe name of the index
*expressionsColumn expressions to include in the index. The expressions are normally instances of _schema.Column, but may also be arbitrary SQL expressions which ultimately refer to a _schema.Column.
**kwAdditional keyword arguments not mentioned above are dialect specific, and passed in the form <dialectname>_<argname>. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments.
unique=​FalseKeyword only argument; if True, create a unique index.
quote=​NoneKeyword only argument; whether to apply quoting to the name of the index. Works in the same manner as that of :paramref:`_schema.Column.quote`.
info=​None

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

New in version 1.0.0.
def __repr__(self):
def _set_parent(self, table, **kw):
Associate with this SchemaEvent's parent object.
def create(self, bind=None, checkfirst=False):

Issue a CREATE statement for this .Index, using the given .Connectable for connectivity.

Note

the "bind" argument will be required in SQLAlchemy 2.0.

See Also

_schema.MetaData.create_all.

def drop(self, bind=None, checkfirst=False):

Issue a DROP statement for this .Index, using the given .Connectable for connectivity.

Note

the "bind" argument will be required in SQLAlchemy 2.0.

See Also

_schema.MetaData.drop_all.

__visit_name__: str =
expressions =

Undocumented

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.

name =

Undocumented

table =

Undocumented

unique =

Undocumented

@property
bind =
Return the connectable associated with this Index.