Fuzzycomplete DuckDB Extension
The fuzzycomplete
extension, developed by Query.Farm, is an alternative to DuckDB’s built-in autocomplete
extension, offering a different approach to SQL completion with several notable distinctions:
DuckDB extensions are plugins that expand the core DuckDB engine with new capabilities.
Algorithm
Instead of relying on traditional edit distance metrics, fuzzycomplete
uses a fuzzy string matching algorithm inspired by Visual Studio Code. This results in more intuitive, flexible, and forgiving suggestions—especially helpful when dealing with partial or misspelled input.
Scope
fuzzycomplete
supports completion of table names across multiple attached databases and schemas. It respects the current search path and provides context-aware suggestions based on all available sources, not just the default database.
Status
While it may not yet offer full-featured SQL statement completion, fuzzycomplete
has proven valuable in practical use and continues to evolve. It has already been useful to its author and may serve as a foundation for more advanced autocomplete functionality in the future.
Getting Started
Fuzzycomplete is a DuckDB community extension maintained and supported by Query.Farm.
Install Fuzzycomplete in DuckDB by running:
FROM community; INSTALL fuzzycomplete
Then load it with:
LOAD fuzzycomplete;
Matching Algorithm
This extension uses the Rust crate code-fuzzy-match
.
The algorithm ensures that characters in the query string appear in the same order in the target string. It handles substring queries efficiently, allowing searches within the middle of the target string without significantly impacting the match score. The algorithm prioritizes matches that occur at the beginning of words, where words are defined as they commonly appear in code (e.g., letters following a separator or in camel case). Sequential matches are also given preference.
In addition to the basic matching algorithm, matches then scored using this criteria if they have an equal score from `code-fuzzy-match``:
- In the event of a tie in the match score, completion results are first ordered by the number of pseudo-words in the candidate strings, favoring shorter completions.
- A standard lexical sorting is then applied.
Love ❤️ this DuckDB extension? You’ll Love This.
Get the best from Query.Farm — smart tips, powerful tools, and project updates sent directly to your inbox, but only when we’ve got something great to share.