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.

Safe where LOWER(name) LIKE '%${search}%'?

See original GitHub issue

I’m trying to build a query for a case insensitive search on the name column. I couldn’t figure out how to do it “safely” with the knex query builder.

Following doesn’t work:

qb.where('LOWER(name)', 'LIKE', `'%${search}%'`)

I could do

qb.whereRaw(`LOWER(name) LIKE '%${search}%'`)

But I have to worry about escaping search.

qb.whereRaw(`LOWER(name) LIKE ?`)

would probably be better but I’m not sure where I can assign ?.

Thanks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
minaairsupportcommented, May 21, 2020

try Ilike instead of like qb.where(‘name’, ‘ILIKE’, '%${search}%')

5reactions
rhys-vdwcommented, Jun 28, 2016

You can check out the whereRaw documentation in the Knex docs.

qb.whereRaw(`LOWER(name) LIKE ?`, [`%${search}%`])
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I search (case-insensitive) in a column using LIKE ...
This is the example of a simple LIKE query: SELECT * FROM <table> WHERE <key> LIKE '%<searchpattern>%'. Now, case-insensitive using LOWER() func:
Read more >
How to Use LIKE Comparison Operator in SQL SELECT ...
Practice #3: Use LIKE operator for lower-case character search. -- Retrieve all products which product name begins with -- lower-case letter c
Read more >
How to do case-insensitive and accent-insensitive search in ...
Refer to the documentation for a complete list. Lowercase comes after uppercase in a binary collation and all the names in the table...
Read more >
LOWER(name) queries perform badly; add column ... - Drupal
The solution I am proposing involves adding a column to the users table, name_lower, which contains an already lowercase version of name. The ......
Read more >
Examples of query criteria - Microsoft Support
Query criteria are also referred to as expressions in Access. ... where the Price or UnitsInStock field contains a value greater than 25...
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