Ruby on rails Rails和fuzzystrmatch PostgreSQL扩展

Ruby on rails Rails和fuzzystrmatch PostgreSQL扩展,ruby-on-rails,ruby,postgresql,Ruby On Rails,Ruby,Postgresql,在我的Rails应用程序中,我正在搜索名与Mike不同的记录: Person.last.where("difference(first_name, ?) < 2", "MIKE") 但是有没有办法在个人记录上使用此差异功能,而不是在集合上检查某个人记录是否具有有效的名字?假设您知道要通过id检查的记录: Person.where( "id = ? AND difference(first_name, ?) < 2", 5, "MIKE" ).to_sql #⇒ "SELECT

在我的Rails应用程序中,我正在搜索名与Mike不同的记录:

Person.last.where("difference(first_name, ?) < 2", "MIKE")

但是有没有办法在个人记录上使用此差异功能,而不是在集合上检查某个人记录是否具有有效的名字?

假设您知道要通过id检查的记录:

Person.where(
  "id = ? AND difference(first_name, ?) < 2", 5, "MIKE"
).to_sql
#⇒ "SELECT `users`.* FROM `users` 
#      WHERE (id = 5 AND difference(first_name, 'MIKE') < 2)" 
添加上述sql是为了演示将在实际环境中执行和删除的查询