Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Paul told you about <a href="https://www.postgresql.org/docs/9.5/static/fuzzystrmatch.html#AEN169796" rel="nofollow noreferrer"><code>levenshtein()</code></a>. That's a very useful tool, but it's also very slow with big tables. It has to calculate the levenshtein-distance from the search term for every single row, that's expensive. </p> <p>First off, <em>if</em> your requirements are as simple as the example indicates, you can still use <code>LIKE</code>. Just replace any <code>-</code> in your search term with <code>%</code> to create the <code>WHERE</code> clause</p> <pre><code>WHERE code LIKE "%AB%123%lHdfj%" </code></pre> <p>instead of </p> <pre><code>WHERE code LIKE "%AB-123-lHdfj%" </code></pre> <p>If your real problem is <strong>more complex</strong> and you need something faster then - depending on your requirements - there are several options.</p> <ul> <li><p>There is <a href="http://www.postgresql.org/docs/current/interactive/textsearch.html" rel="nofollow noreferrer">full text search</a>, of course. But this may be an overkill in your case.</p></li> <li><p>A more likely candidate is <a href="http://www.postgresql.org/docs/current/interactive/pgtrgm.html" rel="nofollow noreferrer">pg_trgm</a>. Note that you can combine that with <code>LIKE</code> in PostgreSQL 9.1. See this <a href="http://www.depesz.com/index.php/2011/02/19/waiting-for-9-1-faster-likeilike/" rel="nofollow noreferrer">blog post by Depesz</a>.<br> Also very interesting in this context: the <code>similarity()</code> function or <code>%</code> operator of that module. More:</p> <ul> <li><a href="https://stackoverflow.com/questions/1566717/postgresql-like-query-performance-variations/13452528#13452528">PostgreSQL LIKE query performance variations</a></li> </ul></li> <li><p>Last but not least you can implement a hand-knit solution with a function to <strong>normalize</strong> the strings to be searched. For instance, you could transform <code>AB1-23-lHdfj</code> -> <code>ab123lhdfj</code>, save it in an additional column and search it with search terms that have been transformed the same way. </p> <p>Or use an <a href="http://www.postgresql.org/docs/current/interactive/indexes-expressional.html" rel="nofollow noreferrer">index on an expression</a> instead of the redundant column. (Involved functions must be <code>IMMUTABLE</code>.) And possibly combine that with <code>pg_tgrm</code> from above.</p></li> </ul> <p>Overview of pattern-matching techniques:</p> <ul> <li><a href="https://dba.stackexchange.com/questions/10694/pattern-matching-with-like-similar-to-or-regular-expressions-in-postgresql/10696#10696">Pattern matching with LIKE, SIMILAR TO or regular expressions in PostgreSQL</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload