summaryrefslogtreecommitdiffstats
path: root/contrib/pg_trgm/pg_trgm--1.3--1.4.sql
blob: 64a0c219b5cbbd9ee01c53a254769c2744ddb9b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* contrib/pg_trgm/pg_trgm--1.3--1.4.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_trgm UPDATE TO '1.4'" to load this file. \quit

CREATE FUNCTION strict_word_similarity(text,text)
RETURNS float4
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

CREATE FUNCTION strict_word_similarity_op(text,text)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT STABLE PARALLEL SAFE;  -- stable because depends on pg_trgm.word_similarity_threshold

CREATE FUNCTION strict_word_similarity_commutator_op(text,text)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT STABLE PARALLEL SAFE;  -- stable because depends on pg_trgm.word_similarity_threshold

CREATE OPERATOR <<% (
        LEFTARG = text,
        RIGHTARG = text,
        PROCEDURE = strict_word_similarity_op,
        COMMUTATOR = '%>>',
        RESTRICT = contsel,
        JOIN = contjoinsel
);

CREATE OPERATOR %>> (
        LEFTARG = text,
        RIGHTARG = text,
        PROCEDURE = strict_word_similarity_commutator_op,
        COMMUTATOR = '<<%',
        RESTRICT = contsel,
        JOIN = contjoinsel
);

CREATE FUNCTION strict_word_similarity_dist_op(text,text)
RETURNS float4
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

CREATE FUNCTION strict_word_similarity_dist_commutator_op(text,text)
RETURNS float4
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

CREATE OPERATOR <<<-> (
        LEFTARG = text,
        RIGHTARG = text,
        PROCEDURE = strict_word_similarity_dist_op,
        COMMUTATOR = '<->>>'
);

CREATE OPERATOR <->>> (
        LEFTARG = text,
        RIGHTARG = text,
        PROCEDURE = strict_word_similarity_dist_commutator_op,
        COMMUTATOR = '<<<->'
);

ALTER OPERATOR FAMILY gist_trgm_ops USING gist ADD
        OPERATOR        9       %>> (text, text),
        OPERATOR        10       <->>> (text, text) FOR ORDER BY pg_catalog.float_ops;

ALTER OPERATOR FAMILY gin_trgm_ops USING gin ADD
        OPERATOR        9       %>> (text, text);