| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | imchifan(at)163(dot)com |
| Subject: | BUG #19951: levenshtein_less_equal returns 0 when exact distance is 1 with a negative cost |
| Date: | 2026-11-25 17:38:01 |
| Message-ID: | 19951-00a787789853f03c@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19951
Logged by: Qifan Liu
Email address: imchifan(at)163(dot)com
PostgreSQL version: 19.0
Operating system: Linux/amd64
Description:
Hi,
levenshtein_less_equal() can return a value that is not greater than max_d
even though the corresponding exact distance exceeds max_d. The functions
accept the negative edit cost used here, and the fuzzystrmatch documentation
does not prohibit negative costs.
Run this as a superuser.
The following can be run in a database where fuzzystrmatch is not already
installed:
\pset tuples_only on
\pset format unaligned
CREATE EXTENSION fuzzystrmatch;
WITH r AS (
SELECT levenshtein('a', 'b', -1, 2, 2) AS exact_distance,
levenshtein_less_equal('a', 'b', -1, 2, 2, 0) AS bounded_distance
)
SELECT exact_distance,
bounded_distance,
exact_distance > 0 AND bounded_distance <= 0 AS contract_violation
FROM r;
DROP EXTENSION fuzzystrmatch;
The output is:
Output format is unaligned.
CREATE EXTENSION
1|0|t
DROP EXTENSION
Since exact_distance is 1 and max_d is 0, bounded_distance should be greater
than 0, but it is 0.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | PG Bug reporting form | 2026-11-25 17:42:11 | BUG #19952: psql \d+ omits nondefault replica identity for partitioned tables |
| Previous Message | PG Bug reporting form | 2026-11-25 17:34:05 | BUG #19950: pg_terminate_backend rejects a positive bigint timeout as negative |