Consider a declarative SQLAlchemy model with an indexed String field:
class User(Base):
name = Column(String(100), index=True, nullable=False)
The name field is case sensitive, meaning the original case should be preserved, but efficient case-insensitive queries on the index should be supported.
What's the best way to achieve this and implement in SQLAlchemy?
Queries can use lower() if needed
session.query(User).filter_by(name=lower('SOME_name'))
but it doesn't matter too much, as long as the solution is elegant and performant.
Queries using ILIKE and Postgres-level lower() are unacceptable due to performance requirements, they've been tested and do not perform fast enough on large tables for my use case.