Answer the question
In order to leave comments, you need to log in
How to make Cyrillic case-insensitive search work in SQLAlchemy/Postgres?
I am using SQLAlchemy and PostgreSQL DBMS.
Let there be:
class Product(db.Model):
__tablename__ = 'products'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
def __init__(self, name):
self.name = name
>>> p1 = models.Product(u'Курага')
>>> db.session.add(p1)
>>> db.session.commit()
>>> p2 = models.Product(u'Apple')
>>> db.session.add(p2)
>>> db.session.commit()
>>> from sqlalchemy import func
>>> db.session.query(models.Product).filter(func.lower(models.Product.name) == u'курага').all()
[]
>>> db.session.query(models.Product).filter(func.lower(models.Product.name) == u'apple').all()
[<app.models.Product object at 0x1035f4310>]
>>> db.session.query(models.Product).filter(models.Product.name.ilike(u'%курага%')).all()
[]
>>> db.session.query(models.Product).filter(models.Product.name.ilike(u'%apple%')).all()
[<app.models.Product object at 0x103b2c210>]
Answer the question
In order to leave comments, you need to log in
Helped:
psql (9.4.1)
Type "help" for help.
postgres=# CREATE DATABASE dbname ENCODING 'UTF-8' LC_COLLATE 'ru_RU.UTF-8' LC_CTYPE 'ru_RU.UTF-8' TEMPLATE=template0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question