Finding similar strings with PostgreSQL quickly
I need to create a ranking of similar strings in a table. I have the following table create table names ( name character varying(255) ); Currently, I'm using pg_trgm module which offers the similarity function, but I have an efficiency problem. I created an index like the Postgres manual suggests : CREATE INDEX trgm_idx ON names USING gist (name gist_trgm_ops); and I'm executing the following query: select (similarity(n1.name, n2.name)) as sim, n1.name, n2.name from names n1, names n2 where n1.name != n2.name and similarity(n1.name, n2.name) > .8 order by sim desc; The query works, but is