针对PostgreSQL
- 函数索引
class test_table(db.Model): username = db.Column(String(20)) __table_args_ = (Index('idx_username', func.lower('username'), unique=True), ) # 生成SQL如下: # create unique index idx_username on test_table lower(username)
- 指定索引类型
__table_args__ = (Index('idx_point', 'point', postgresql_using='gist'), ) # 生成SQL: # create index idx_point on table_name using gist(point)
- 条件索引
__table_args__ = (Index('idx_where', 'column', postgresql_where = model.c.column > 10), ) # 生成SQL: # create index idx_where on table_name (column) where column > 10