2011-02-14 04:06:41 +03:00
|
|
|
/* contrib/pg_trgm/pg_trgm--1.0.sql */
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2011-10-12 23:45:03 +04:00
|
|
|
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
|
|
|
\echo Use "CREATE EXTENSION pg_trgm" to load this file. \quit
|
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION set_limit(float4)
|
2007-11-11 06:25:35 +03:00
|
|
|
RETURNS float4
|
2004-05-31 21:18:12 +04:00
|
|
|
AS 'MODULE_PATHNAME'
|
2007-12-09 05:22:46 +03:00
|
|
|
LANGUAGE C STRICT VOLATILE;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION show_limit()
|
2007-11-11 06:25:35 +03:00
|
|
|
RETURNS float4
|
2004-05-31 21:18:12 +04:00
|
|
|
AS 'MODULE_PATHNAME'
|
2007-12-09 05:22:46 +03:00
|
|
|
LANGUAGE C STRICT STABLE;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION show_trgm(text)
|
2007-11-11 06:25:35 +03:00
|
|
|
RETURNS _text
|
2004-05-31 21:18:12 +04:00
|
|
|
AS 'MODULE_PATHNAME'
|
2007-09-30 19:52:06 +04:00
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION similarity(text,text)
|
2007-11-11 06:25:35 +03:00
|
|
|
RETURNS float4
|
2004-05-31 21:18:12 +04:00
|
|
|
AS 'MODULE_PATHNAME'
|
2007-09-30 19:52:06 +04:00
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION similarity_op(text,text)
|
2007-11-11 06:25:35 +03:00
|
|
|
RETURNS bool
|
2004-05-31 21:18:12 +04:00
|
|
|
AS 'MODULE_PATHNAME'
|
2010-12-04 08:16:21 +03:00
|
|
|
LANGUAGE C STRICT STABLE; -- stable because depends on trgm_limit
|
2004-05-31 21:18:12 +04:00
|
|
|
|
|
|
|
CREATE OPERATOR % (
|
|
|
|
LEFTARG = text,
|
|
|
|
RIGHTARG = text,
|
|
|
|
PROCEDURE = similarity_op,
|
|
|
|
COMMUTATOR = '%',
|
|
|
|
RESTRICT = contsel,
|
|
|
|
JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION similarity_dist(text,text)
|
2010-12-04 08:16:21 +03:00
|
|
|
RETURNS float4
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR <-> (
|
|
|
|
LEFTARG = text,
|
|
|
|
RIGHTARG = text,
|
|
|
|
PROCEDURE = similarity_dist,
|
|
|
|
COMMUTATOR = '<->'
|
|
|
|
);
|
|
|
|
|
2007-03-14 17:15:40 +03:00
|
|
|
-- gist key
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gtrgm_in(cstring)
|
2004-05-31 21:18:12 +04:00
|
|
|
RETURNS gtrgm
|
|
|
|
AS 'MODULE_PATHNAME'
|
2007-09-30 19:52:06 +04:00
|
|
|
LANGUAGE C STRICT;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gtrgm_out(gtrgm)
|
2004-05-31 21:18:12 +04:00
|
|
|
RETURNS cstring
|
|
|
|
AS 'MODULE_PATHNAME'
|
2007-09-30 19:52:06 +04:00
|
|
|
LANGUAGE C STRICT;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
|
|
|
CREATE TYPE gtrgm (
|
|
|
|
INTERNALLENGTH = -1,
|
|
|
|
INPUT = gtrgm_in,
|
|
|
|
OUTPUT = gtrgm_out
|
|
|
|
);
|
|
|
|
|
2007-03-14 17:15:40 +03:00
|
|
|
-- support functions for gist
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gtrgm_consistent(internal,text,int,oid,internal)
|
2004-05-31 21:18:12 +04:00
|
|
|
RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME'
|
2009-06-11 22:30:03 +04:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2010-11-23 23:27:50 +03:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gtrgm_distance(internal,text,int,oid)
|
2010-12-04 08:16:21 +03:00
|
|
|
RETURNS float8
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gtrgm_compress(internal)
|
2004-05-31 21:18:12 +04:00
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
2009-06-11 22:30:03 +04:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gtrgm_decompress(internal)
|
2004-05-31 21:18:12 +04:00
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
2009-06-11 22:30:03 +04:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gtrgm_penalty(internal,internal,internal)
|
2004-05-31 21:18:12 +04:00
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
2009-06-11 22:30:03 +04:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gtrgm_picksplit(internal, internal)
|
2004-05-31 21:18:12 +04:00
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
2009-06-11 22:30:03 +04:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gtrgm_union(bytea, internal)
|
2004-05-31 21:18:12 +04:00
|
|
|
RETURNS _int4
|
|
|
|
AS 'MODULE_PATHNAME'
|
2009-06-11 22:30:03 +04:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gtrgm_same(gtrgm, gtrgm, internal)
|
2004-05-31 21:18:12 +04:00
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
2009-06-11 22:30:03 +04:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2004-05-31 21:18:12 +04:00
|
|
|
|
2007-03-14 17:15:40 +03:00
|
|
|
-- create the operator class for gist
|
2004-05-31 21:18:12 +04:00
|
|
|
CREATE OPERATOR CLASS gist_trgm_ops
|
|
|
|
FOR TYPE text USING gist
|
|
|
|
AS
|
|
|
|
OPERATOR 1 % (text, text),
|
2008-04-14 21:05:34 +04:00
|
|
|
FUNCTION 1 gtrgm_consistent (internal, text, int, oid, internal),
|
2004-05-31 21:18:12 +04:00
|
|
|
FUNCTION 2 gtrgm_union (bytea, internal),
|
|
|
|
FUNCTION 3 gtrgm_compress (internal),
|
|
|
|
FUNCTION 4 gtrgm_decompress (internal),
|
|
|
|
FUNCTION 5 gtrgm_penalty (internal, internal, internal),
|
|
|
|
FUNCTION 6 gtrgm_picksplit (internal, internal),
|
|
|
|
FUNCTION 7 gtrgm_same (gtrgm, gtrgm, internal),
|
|
|
|
STORAGE gtrgm;
|
|
|
|
|
2011-02-17 23:03:30 +03:00
|
|
|
-- Add operators and support functions that are new in 9.1. We do it like
|
|
|
|
-- this, leaving them "loose" in the operator family rather than bound into
|
|
|
|
-- the gist_trgm_ops opclass, because that's the only state that can be
|
|
|
|
-- reproduced during an upgrade from 9.0 (see pg_trgm--unpackaged--1.0.sql).
|
|
|
|
|
|
|
|
ALTER OPERATOR FAMILY gist_trgm_ops USING gist ADD
|
|
|
|
OPERATOR 2 <-> (text, text) FOR ORDER BY pg_catalog.float_ops,
|
|
|
|
OPERATOR 3 pg_catalog.~~ (text, text),
|
|
|
|
OPERATOR 4 pg_catalog.~~* (text, text),
|
|
|
|
FUNCTION 8 (text, text) gtrgm_distance (internal, text, int, oid);
|
|
|
|
|
2007-03-14 17:15:40 +03:00
|
|
|
-- support functions for gin
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gin_extract_value_trgm(text, internal)
|
2007-03-14 17:15:40 +03:00
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
2009-06-11 22:30:03 +04:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2007-03-14 17:15:40 +03:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gin_extract_query_trgm(text, internal, int2, internal, internal, internal, internal)
|
2007-03-14 17:15:40 +03:00
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
2009-06-11 22:30:03 +04:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2007-03-14 17:15:40 +03:00
|
|
|
|
2011-02-14 05:24:14 +03:00
|
|
|
CREATE FUNCTION gin_trgm_consistent(internal, int2, text, int4, internal, internal, internal, internal)
|
2009-03-26 01:19:02 +03:00
|
|
|
RETURNS bool
|
2007-03-14 17:15:40 +03:00
|
|
|
AS 'MODULE_PATHNAME'
|
2009-06-11 22:30:03 +04:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2007-03-14 17:15:40 +03:00
|
|
|
|
|
|
|
-- create the operator class for gin
|
|
|
|
CREATE OPERATOR CLASS gin_trgm_ops
|
|
|
|
FOR TYPE text USING gin
|
|
|
|
AS
|
2008-04-14 21:05:34 +04:00
|
|
|
OPERATOR 1 % (text, text),
|
2007-03-14 17:15:40 +03:00
|
|
|
FUNCTION 1 btint4cmp (int4, int4),
|
2011-02-01 05:33:55 +03:00
|
|
|
FUNCTION 2 gin_extract_value_trgm (text, internal),
|
|
|
|
FUNCTION 3 gin_extract_query_trgm (text, internal, int2, internal, internal, internal, internal),
|
|
|
|
FUNCTION 4 gin_trgm_consistent (internal, int2, text, int4, internal, internal, internal, internal),
|
2007-03-14 17:15:40 +03:00
|
|
|
STORAGE int4;
|
2011-02-17 23:03:30 +03:00
|
|
|
|
|
|
|
-- Add operators that are new in 9.1.
|
|
|
|
|
|
|
|
ALTER OPERATOR FAMILY gin_trgm_ops USING gin ADD
|
|
|
|
OPERATOR 3 pg_catalog.~~ (text, text),
|
|
|
|
OPERATOR 4 pg_catalog.~~* (text, text);
|