ruby - ActiveRecord "lower(column_name)" is still case sensitive. (MySql2, Rails) -


i using mysql2 in rails application. trying make activerecord query returns records have specified fields containing string. have read downcasing input , using lower(column_name) 'string' should trick, this not appear work. query follows:

search = params[:search].to_s.downcase  @current_user.patients.where("lower(last_name) ? or lower(first_name) ? or lower(identifier) ?", "%#{search}%", "%#{search}%", "%#{search}%") 

let's have record last name "abbott". when search param "abb" or "bot", record returned. however, when search param "abb" or "bot", nothing returned. appears query still case sensitive??

i have looked on , cannot seem find answer. have read multiple times lower(column_name) should work, not.

any appreciated. thanks!

i figured out. indeed because fields stored binary values (thanks vincent). casting binary fields chars, able case-insensitively compare them:

@current_user.patients.where("cast(last_name char) ? or ...


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -