R
R
Rudolf Nemov2020-08-18 19:05:42
Python
Rudolf Nemov, 2020-08-18 19:05:42

How to implement case insensitive search in python?

In an asynchronous web application, I make case-insensitive queries against a database (aiosqlite) to look up a full name from a list of real-time profiles:

async def query(*args):
    name,lastname = [x.upper()+"%" for x in args]
    async with aiosqlite.connect(Host.DBPATH) as db:
            cursor = await db.execute("SELECT * FROM profile WHERE UPPER(name) LIKE ? OR UPPER(lastname) LIKE ?",(name,lastname))
            return await cursor.fetchall()


Like many, it was a surprise to me that the search in Russian would not work.
I would like to ask how to implement an asynchronous case-insensitive search on several database fields (currently sqlite, but you can move)?

If I understand correctly, aiosqlite does not support other encodings, right?

NO CASE COLLATE tried - does not work.

The app is connected to heroku via pipelines.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Pankov, 2020-08-18
@rudieduddie

You can, as a quick solution, duplicate the data in the table, processing it from the outside with an upper case transformation.
Then you will have to submit already converted (prepared for the index format) data to the input to the queries.
And here there is an article on how to add collate for Russian case-insensitive comparison.

D
Dr. Bacon, 2020-08-18
@bacon

As for many, it was a surprise for me that the search in Russian would not work.
This is a sqlite issue.
You can first create a request with your hands and check the functionality with your hands.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question