2👍
In postgres exists a function for similarity, first create the extension that contains it
create extension pg_trgm;
after that select using a percentage of similarity like this (e.g. 80% or your desired value)
select x from "table" where similarity('abcdefghijklmnop', x)>0.35;
or the most similar string would be
select * from "table" order by similarity('abcdefghijklmnop', x) desc limit 1;
Fiddle http://sqlfiddle.com/#!17/c901e/2 and docs https://www.postgresql.org/docs/current/pgtrgm.html
-1👍
best one i found is this:
SELECT id,
FROM table
WHERE '3552' LIKE prefix || '%'
ORDER BY prefix DESC
LIMIT 1
thank you all
- [Answered ]-@register.filter in my code
- [Answered ]-Why does GET Details returns all Null and Delete Details returns "detail": "Method \"GET\" not allowed." when using objects.filter?
- [Answered ]-Scheduling Filter on Database with Time Interval
- [Answered ]-How to keep searched word on second results page
- [Answered ]-Django and jQuery: timing
Source:stackexchange.com