Declaring functional (func.lower) does not work as expected with declarative

Issue #2799 resolved
Former user created an issue

Attached is a very simple case.

Comments (2)

  1. Mike Bayer repo owner

    the index needs to be associated with at least one column in the table. The string "tag" is not a column, to SQLAlchemy its an arbitrary expression. usage is as follows:

    from sqlalchemy import *
    from sqlalchemy.orm import *
    from sqlalchemy.ext.declarative import declarative_base
    
    Base = declarative_base()
    
    
    class FuncIndex(Base):
        __tablename__ = 'funcindex'
    
        id = Column(Integer, primary_key=True)
        tag = Column(String(20))
        __table_args__ = (
            Index('funcindex_idx', func.lower(tag)),
        )
    
    e = create_engine("postgresql://scott:tiger@localhost/test", echo=True)
    Base.metadata.create_all(e)
    
  2. Log in to comment