sql - PG::InvalidColumnReference: ERROR: for SELECT DISTINCT in Ruby on Rails app -


i have query looks this:

 person.where.not(first_name: nil).where.not("lower(first_name)  = ?", 'mike').order('random()').limit(6).pluck("distinct(lower(first_name))") 

it returns me following error when try run it:

activerecord::statementinvalid: pg::invalidcolumnreference: error:  select distinct, order expressions must appear in select list line 1: ...and (not (lower(first_name)  = 'mike'))  order random() l... 

how can solve problem?

person.where.not(first_name: nil).where.not("lower(first_name)  = ?", 'mike').order('random()').limit(6).select("lower(first_name)").uniq 

since pluck fire query instead of pluck should use select


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -