L
L
lovesuper2014-03-03 09:16:24
Python
lovesuper, 2014-03-03 09:16:24

Is it possible to set Index c func.lower for a model in SQLAlchemy?

class City(Model, Base):

    __tablename__ = 'city'
    __table_args__ = (Index(
                      'city_name_important_btree_ix',
                      'important',
                      func.lower('name'),
                      postgresql_ops={'data': 'text_pattern_ops'}),)

    name = Column(Unicode(255))
    important = Column(Boolean, nullable=False, default=False)

And here is the actual error:
AttributeError: Neither 'Function' object nor 'Comparator' object has an attribute 'key'

Here is the model code with bills and the error. Everything works except wrapping name in func.lower. Google didn't show anything. Maybe someone knows how to make a similar index on the lower case? Googled a way to declare a similar index OUTSIDE the model. But it would be preferable to do it inside.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GreatRash, 2015-06-02
@GreatRash

Read on, everything has already been thought of for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question