Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
182
rated 0 times [  187] [ 5]  / answers: 1 / hits: 39349  / 8 Years ago, tue, september 13, 2016, 12:00:00

I am trying to create the following query using knex:



SELECT * FROM users group by users.location having users.photo is not null



as follows:



knex(users).groupBy(users.location).having(users.photo, IS NOT, Null)



I am getting the following error on this:



The operator IS NOT is not permitted



I've gone through their documentation and couldn't find anything useful.


More From » mysql

 Answers
4

According to the docs, .havingRaw is what you need:



knex(users).groupBy(users.location).havingRaw(users.photo IS NOT ?, [null]);


On the other hand, do a knex.raw at once unless there is any remaining advantage using the builder on this specific case.


[#60734] Friday, September 9, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dexter

Total Points: 717
Total Questions: 98
Total Answers: 115

Location: Sudan
Member since Thu, May 7, 2020
4 Years ago
;