Skip to content

fzy

FZY algorithm for PostgreSQL

pg_fzy · FZY algorithm for PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100464fzypg_fzy0.0.1FTSMITC

PostgreSQL · 11, 12, 13

Usage

Sources:

fzy exposes the fzy fuzzy-matching score to SQL. Use it to rank a modest set of candidate strings against an abbreviated or partially typed query; it is a scoring function, not an index or a complete search engine.

Core Workflow

Install the extension in the database, then calculate a score for each candidate and sort the result. The second argument must be converted to PostgreSQL’s C-string pseudo-type.

CREATE EXTENSION fzy;

SELECT name,
       fzy('Stev', name::cstring) AS score
FROM users
ORDER BY score DESC;

Higher scores are better matches. Version 0.0.1 implements only the case-insensitive form of the fzy algorithm.

SQL Object

  • fzy(cstring, cstring) RETURNS integer computes the match score.

The function is declared strict, so a null argument produces null. It is also declared volatile by the extension SQL, which may limit planner optimizations. Because no index operator or access method is provided, PostgreSQL evaluates the function for every candidate row selected by the query.

Table reader