class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem):
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)")) )
_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 |
Parameters | |
name | The name of the index |
*expressions | Column 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 . |
**kw | Additional 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=False | Keyword only argument; if True, create a unique index. |
quote=None | Keyword 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
New in version 1.0.0.
|
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
.
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
.
sqlalchemy.sql.schema.SchemaItem.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
.