mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-19 23:53:26 +02:00
It was never terribly consistent to use OR REPLACE (because of the lack of comparable functionality for data types, operators, etc), and experimentation shows that it's now positively pernicious in the extension world. We really want a failure to occur if there are any conflicts, else it's unclear what the extension-ownership state of the conflicted object ought to be. Most of the time, CREATE EXTENSION will fail anyway because of conflicts on other object types, but an extension defining only functions can succeed, with bad results.
153 lines
4.3 KiB
SQL
153 lines
4.3 KiB
SQL
/* contrib/pg_trgm/pg_trgm--1.0.sql */
|
|
|
|
CREATE FUNCTION set_limit(float4)
|
|
RETURNS float4
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT VOLATILE;
|
|
|
|
CREATE FUNCTION show_limit()
|
|
RETURNS float4
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT STABLE;
|
|
|
|
CREATE FUNCTION show_trgm(text)
|
|
RETURNS _text
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
CREATE FUNCTION similarity(text,text)
|
|
RETURNS float4
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
CREATE FUNCTION similarity_op(text,text)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT STABLE; -- stable because depends on trgm_limit
|
|
|
|
CREATE OPERATOR % (
|
|
LEFTARG = text,
|
|
RIGHTARG = text,
|
|
PROCEDURE = similarity_op,
|
|
COMMUTATOR = '%',
|
|
RESTRICT = contsel,
|
|
JOIN = contjoinsel
|
|
);
|
|
|
|
CREATE FUNCTION similarity_dist(text,text)
|
|
RETURNS float4
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
CREATE OPERATOR <-> (
|
|
LEFTARG = text,
|
|
RIGHTARG = text,
|
|
PROCEDURE = similarity_dist,
|
|
COMMUTATOR = '<->'
|
|
);
|
|
|
|
-- gist key
|
|
CREATE FUNCTION gtrgm_in(cstring)
|
|
RETURNS gtrgm
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT;
|
|
|
|
CREATE FUNCTION gtrgm_out(gtrgm)
|
|
RETURNS cstring
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT;
|
|
|
|
CREATE TYPE gtrgm (
|
|
INTERNALLENGTH = -1,
|
|
INPUT = gtrgm_in,
|
|
OUTPUT = gtrgm_out
|
|
);
|
|
|
|
-- support functions for gist
|
|
CREATE FUNCTION gtrgm_consistent(internal,text,int,oid,internal)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gtrgm_distance(internal,text,int,oid)
|
|
RETURNS float8
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gtrgm_compress(internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gtrgm_decompress(internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gtrgm_penalty(internal,internal,internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gtrgm_picksplit(internal, internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gtrgm_union(bytea, internal)
|
|
RETURNS _int4
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gtrgm_same(gtrgm, gtrgm, internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
-- create the operator class for gist
|
|
CREATE OPERATOR CLASS gist_trgm_ops
|
|
FOR TYPE text USING gist
|
|
AS
|
|
OPERATOR 1 % (text, text),
|
|
OPERATOR 2 <-> (text, text) FOR ORDER BY pg_catalog.float_ops,
|
|
OPERATOR 3 pg_catalog.~~ (text, text),
|
|
OPERATOR 4 pg_catalog.~~* (text, text),
|
|
FUNCTION 1 gtrgm_consistent (internal, text, int, oid, internal),
|
|
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),
|
|
FUNCTION 8 gtrgm_distance (internal, text, int, oid),
|
|
STORAGE gtrgm;
|
|
|
|
-- support functions for gin
|
|
CREATE FUNCTION gin_extract_value_trgm(text, internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gin_extract_query_trgm(text, internal, int2, internal, internal, internal, internal)
|
|
RETURNS internal
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
CREATE FUNCTION gin_trgm_consistent(internal, int2, text, int4, internal, internal, internal, internal)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
-- create the operator class for gin
|
|
CREATE OPERATOR CLASS gin_trgm_ops
|
|
FOR TYPE text USING gin
|
|
AS
|
|
OPERATOR 1 % (text, text),
|
|
OPERATOR 3 pg_catalog.~~ (text, text),
|
|
OPERATOR 4 pg_catalog.~~* (text, text),
|
|
FUNCTION 1 btint4cmp (int4, int4),
|
|
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),
|
|
STORAGE int4;
|