I have to use the LOWER
function in whereIn
using knex. I want to change the below line of code
whereIn("name", members);
If I do whereIn('LOWER("name")', members);
, getting error as Column LOWER("name") is not present.
I tried to use knex.raw but again not getting the correct syntax.
const roleMembers = await t("roles")
.select({ role_id: "id" }, "name")
.whereIn(t.raw("LOWER('name')"), members);
When I try to add await, syntax error goes away but when I execute this code I get the below error
error: LOWER(name) - syntax error at or near "LOWER"
I'm referring http://knexjs.org/#Builder-whereIn
We have whereRaw
, Do we have a similar thing for whereIn
? Need some help to fix this issue.
Note: I used all LOWER, lower, Lower.
knex.raw()
可用于列组件
knex('members').whereIn(knex.raw('Lower("name")'), members)
select * from `members` where Lower("name") in ('Tom', 'Dick', 'harry')
The final solution is below.
const roleMembers = await t("roles")
.select({ role_id: "id" }, "name")
.whereIn(t.raw('LOWER("name")') as any, members);
My changes to the original code are
Thanks Matt and Mikael for guidance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.