Reputation: 4416
Is it possible to list all indices in a db using sqlalchemy?
Upvotes: 10
Views: 4308
Reputation: 2183
A little update to @nosklo's answer which is deprecated since SQLAlchemy 1.4.
New code should be:
from sqlalchemy import create_engine, inspect
engine = create_engine("...")
insp = inspect(engine)
for name in insp.get_table_names():
for index in insp.get_indexes(name):
print(index)
Note you can also use a Connection
object as argument to inspect
- can be more convenient in some cases.
Upvotes: 2