Unable to create tsvector functional index

Issue #2800 resolved
Devon Meunier created an issue
class Organization(Base):
    __tablename__ = 'organization'

    id = Column(Integer, primary_key=True)
    name = Column(Unicode, unique=True)
    business_number = Column(Unicode(255), unique=True)
    website = Column(Unicode)

    is_donor = Column(Boolean, nullable=False, default=False)
    is_member = Column(Boolean, nullable=False, default=False)

    __table_args__ = (
        Index(
            'organization_name_search_ix',
            func.to_tsvector('english', func.lower(name)),
            postgresql_using='gin'
        ),
    )

Produces the following mangled SQL output:

2013-08-14 15:56:58,170 INFO  [sqlalchemy.engine.base.Engine](sqlalchemy.engine.base.Engine)[MainThread](MainThread) {}
2013-08-14 15:56:58,191 INFO  [sqlalchemy.engine.base.Engine](sqlalchemy.engine.base.Engine)[MainThread](MainThread) COMMIT
2013-08-14 15:56:58,194 INFO  [sqlalchemy.engine.base.Engine](sqlalchemy.engine.base.Engine)[MainThread](MainThread) CREATE INDEX organization_name_search_ix ON organization USING gin (to_tsvector(%(to_tsvector_1)s, lower(name)))
2013-08-14 15:56:58,194 INFO  [sqlalchemy.engine.base.Engine](sqlalchemy.engine.base.Engine)[MainThread](MainThread) {}
2013-08-14 15:56:58,194 INFO  [sqlalchemy.engine.base.Engine](sqlalchemy.engine.base.Engine)[MainThread](MainThread) ROLLBACK

Comments (1)

  1. Mike Bayer repo owner

    you can't use bound parameters in DDL, #2742 looks to improve this so this is a duplicate.

        __table_args__ = (
            Index(
                'organization_name_search_ix',
                func.to_tsvector(text("'english'"), func.lower(name)),
                postgresql_using='gin'
            ),
        )
    
  2. Log in to comment