Safe where LOWER(name) LIKE '%${search}%'?
See original GitHub issueI’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:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
try
Ilike
instead of like qb.where(‘name’, ‘ILIKE’,'%${search}%'
)You can check out the
whereRaw
documentation in the Knex docs.