0

I have a tiny dataset (~1000 rows). Each row has a username, first name and last name. Can I do a fuzzy search on these three fields by using pg_trgm and concatenating the three fields together with two spaces between each? Alternatively, is there a better method to search through this set of users, using trigrams or any other method?

Shien
  • 495
  • 5
  • 13

1 Answers1

2
select format('%s  %s  %s', username, first_name, last_name)
from t
order by greatest (
    similarity(_name, username),
    similarity(_name, first_name),
    similarity(_name, last_name)
) desc
limit 10

or

select s
from t, format('%s  %s  %s', username, first_name, last_name) s(s)
order by word_similarity(_name, s) desc
limit 10
Clodoaldo Neto
  • 118,695
  • 26
  • 233
  • 260