Extensions/Modules in Postgres?
-
A extension is a modular package of SQL objects, functions, and compiled
code that adds extra features or capabilities to your database that
aren't available in the core distribution
What is pg_trgm/Trigram/Trigraph module
-
What is Alphanumeric text?
Alpha(alphabet) and numeric(number).
This character set that includes both letters (A-Z, both uppercase and lowercase) and numbers (0-9).
It can also include punctuation marks and other special symbols (like @, #, or &)
Eg: 3B9-XF4
What is a trigram?
-
Trigram is a contigous sequence of 3 or less characters taken from a
string.
Each word is considered to have two spaces prefixed and one space suffixed when determining the set of trigrams contained in the string.
| String | Trigrams |
|---|---|
| "cat" | “ c”, “ ca”, “cat”, and “at ” |
| “foo|bar” | “ f”, “ fo”, “foo”, “oo ”, “ b”, “ ba”, “bar”, and “ar ” |
Functions provided by pg_trgm module
| Function | Description |
|---|---|
| similarity ( text, text ) → real |
Returns a number that indicates how similar the two arguments are.
The range of the result is zero (indicating that the two strings are
completely dissimilar) to one (indicating that the two strings are
identical).
|
| word_similarity ( text, text ) → real | Returns a number that indicates the greatest similarity between the set of trigrams in the first string and any continuous extent of an ordered set of trigrams in the second string. |
Operators provided by pg_trgm module
| Operator | Description |
|---|---|
| text % text → boolean | Returns true if its arguments have a similarity that is greater than the current similarity threshold set by pg_trgm.similarity_threshold. |
| GiST and GIN index operator |
pg_trgm module provides GiST and GIN index operator classes that
allow you to create an index over a text column for the purpose of
very fast similarity searches.
|