question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proper way to make a case-insensitive query on a string column?

See original GitHub issue

I have an entity with a string column, and I’m importing external data into the table. I want to be able to do a case-insensitive query against the column, because it’s based on user input.

I’d like to know if there’s a way other than normalizing my data in the db to lowercase (which would be inconvenient because I need to display this string back to the user in its original case) and user query.

I’m using a Repository.find({stringColumn: userInput}) to fetch my data.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

116reactions
manuhortetcommented, Jul 15, 2019

For those using postgres, the ILIKE operator perform case insensitive queries:

Entity.find({
    where: `"column" ILIKE 'keyword'` 
});

* Notice I’m using " " to specify the column and ' ' to specify the searched keyword. Double quotes are used for quoted identifiers and single quotes for string literals

This open issue is about including the ILIKE operator as a typeorm advanced option, which would be the ideal solution for postgres users.

55reactions
pleerockcommented, Nov 27, 2017

I guess you need something like this:

SELECT * FROM `post` WHERE LOWER(`title`) = LOWER("some title")

Can you try to do it following way:

const posts = await repository.createQueryBuilder("post")
     .where("LOWER(post.title) = LOWER(:title)", { title })
     .getMany();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Case insensitive SQL SELECT query examples
The SQL standard way to perform case insensitive queries is to use the SQL upper or lower functions, like this: select * from...
Read more >
How to make "case-insensitive" query in Postgresql?
Use LOWER function to convert the strings to lower case before comparing. Try this: SELECT id FROM groups WHERE LOWER(name)=LOWER('Administrator').
Read more >
Case-Insensitive Search in SQL - Use The Index, Luke
Ignoring the case in a where clause is very simple. You can, for example, convert both sides of the comparison to all caps...
Read more >
How to do case-insensitive and accent-insensitive search in ...
To find all the people who have Barry for any of their names, you can (upper- or) lowercase the column and search string:...
Read more >
Controlling Case Sensitivity in String Comparisons - O'Reilly
In summary, comparisons are case sensitive if they involve a binary literal string or string expression, or a CHAR BINARY , VARCHAR BINARY...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found