Introduce jsonb, a structured format for storing json.
The new format accepts exactly the same data as the json type. However, it is
stored in a format that does not require reparsing the orgiginal text in order
to process it, making it much more suitable for indexing and other operations.
Insignificant whitespace is discarded, and the order of object keys is not
preserved. Neither are duplicate object keys kept - the later value for a given
key is the only one stored.
The new type has all the functions and operators that the json type has,
with the exception of the json generation functions (to_json, json_agg etc.)
and with identical semantics. In addition, there are operator classes for
hash and btree indexing, and two classes for GIN indexing, that have no
equivalent in the json type.
This feature grew out of previous work by Oleg Bartunov and Teodor Sigaev, which
was intended to provide similar facilities to a nested hstore type, but which
in the end proved to have some significant compatibility issues.
Authors: Oleg Bartunov, Teodor Sigaev, Peter Geoghegan and Andrew Dunstan.
Review: Andres Freund
2014-03-24 04:40:19 +08:00
|
|
|
/* contrib/hstore/hstore--1.3.sql */
|
2011-11-08 10:47:45 +08:00
|
|
|
|
|
|
|
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
|
|
|
\echo Use "CREATE EXTENSION hstore" to load this file. \quit
|
|
|
|
|
|
|
|
CREATE TYPE hstore;
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_in(cstring)
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_out(hstore)
|
|
|
|
RETURNS cstring
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_recv(internal)
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_send(hstore)
|
|
|
|
RETURNS bytea
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE TYPE hstore (
|
|
|
|
INTERNALLENGTH = -1,
|
|
|
|
INPUT = hstore_in,
|
|
|
|
OUTPUT = hstore_out,
|
|
|
|
RECEIVE = hstore_recv,
|
|
|
|
SEND = hstore_send,
|
|
|
|
STORAGE = extended
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_version_diag(hstore)
|
|
|
|
RETURNS integer
|
|
|
|
AS 'MODULE_PATHNAME','hstore_version_diag'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION fetchval(hstore,text)
|
|
|
|
RETURNS text
|
|
|
|
AS 'MODULE_PATHNAME','hstore_fetchval'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR -> (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = text,
|
|
|
|
PROCEDURE = fetchval
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION slice_array(hstore,text[])
|
|
|
|
RETURNS text[]
|
|
|
|
AS 'MODULE_PATHNAME','hstore_slice_to_array'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR -> (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = text[],
|
|
|
|
PROCEDURE = slice_array
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION slice(hstore,text[])
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME','hstore_slice_to_hstore'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION isexists(hstore,text)
|
|
|
|
RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME','hstore_exists'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION exist(hstore,text)
|
|
|
|
RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME','hstore_exists'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR ? (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = text,
|
|
|
|
PROCEDURE = exist,
|
|
|
|
RESTRICT = contsel,
|
|
|
|
JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION exists_any(hstore,text[])
|
|
|
|
RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME','hstore_exists_any'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR ?| (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = text[],
|
|
|
|
PROCEDURE = exists_any,
|
|
|
|
RESTRICT = contsel,
|
|
|
|
JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION exists_all(hstore,text[])
|
|
|
|
RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME','hstore_exists_all'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR ?& (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = text[],
|
|
|
|
PROCEDURE = exists_all,
|
|
|
|
RESTRICT = contsel,
|
|
|
|
JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION isdefined(hstore,text)
|
|
|
|
RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME','hstore_defined'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION defined(hstore,text)
|
|
|
|
RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME','hstore_defined'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION delete(hstore,text)
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME','hstore_delete'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION delete(hstore,text[])
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME','hstore_delete_array'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION delete(hstore,hstore)
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME','hstore_delete_hstore'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR - (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = text,
|
|
|
|
PROCEDURE = delete
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR - (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = text[],
|
|
|
|
PROCEDURE = delete
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR - (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = delete
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION hs_concat(hstore,hstore)
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME','hstore_concat'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR || (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hs_concat
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION hs_contains(hstore,hstore)
|
|
|
|
RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME','hstore_contains'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION hs_contained(hstore,hstore)
|
|
|
|
RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME','hstore_contained'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR @> (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hs_contains,
|
|
|
|
COMMUTATOR = '<@',
|
|
|
|
RESTRICT = contsel,
|
|
|
|
JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR <@ (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hs_contained,
|
|
|
|
COMMUTATOR = '@>',
|
|
|
|
RESTRICT = contsel,
|
|
|
|
JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
-- obsolete:
|
|
|
|
CREATE OPERATOR @ (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hs_contains,
|
|
|
|
COMMUTATOR = '~',
|
|
|
|
RESTRICT = contsel,
|
|
|
|
JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR ~ (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hs_contained,
|
|
|
|
COMMUTATOR = '@',
|
|
|
|
RESTRICT = contsel,
|
|
|
|
JOIN = contjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION tconvert(text,text)
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME','hstore_from_text'
|
|
|
|
LANGUAGE C IMMUTABLE; -- not STRICT; needs to allow (key,NULL)
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore(text,text)
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME','hstore_from_text'
|
|
|
|
LANGUAGE C IMMUTABLE; -- not STRICT; needs to allow (key,NULL)
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore(text[],text[])
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME', 'hstore_from_arrays'
|
|
|
|
LANGUAGE C IMMUTABLE; -- not STRICT; allows (keys,null)
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore(text[])
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME', 'hstore_from_array'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
CREATE CAST (text[] AS hstore)
|
|
|
|
WITH FUNCTION hstore(text[]);
|
|
|
|
|
2013-03-11 05:35:36 +08:00
|
|
|
CREATE FUNCTION hstore_to_json(hstore)
|
|
|
|
RETURNS json
|
|
|
|
AS 'MODULE_PATHNAME', 'hstore_to_json'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
CREATE CAST (hstore AS json)
|
|
|
|
WITH FUNCTION hstore_to_json(hstore);
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_to_json_loose(hstore)
|
|
|
|
RETURNS json
|
|
|
|
AS 'MODULE_PATHNAME', 'hstore_to_json_loose'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
Introduce jsonb, a structured format for storing json.
The new format accepts exactly the same data as the json type. However, it is
stored in a format that does not require reparsing the orgiginal text in order
to process it, making it much more suitable for indexing and other operations.
Insignificant whitespace is discarded, and the order of object keys is not
preserved. Neither are duplicate object keys kept - the later value for a given
key is the only one stored.
The new type has all the functions and operators that the json type has,
with the exception of the json generation functions (to_json, json_agg etc.)
and with identical semantics. In addition, there are operator classes for
hash and btree indexing, and two classes for GIN indexing, that have no
equivalent in the json type.
This feature grew out of previous work by Oleg Bartunov and Teodor Sigaev, which
was intended to provide similar facilities to a nested hstore type, but which
in the end proved to have some significant compatibility issues.
Authors: Oleg Bartunov, Teodor Sigaev, Peter Geoghegan and Andrew Dunstan.
Review: Andres Freund
2014-03-24 04:40:19 +08:00
|
|
|
CREATE FUNCTION hstore_to_jsonb(hstore)
|
|
|
|
RETURNS jsonb
|
|
|
|
AS 'MODULE_PATHNAME', 'hstore_to_jsonb'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
CREATE CAST (hstore AS jsonb)
|
|
|
|
WITH FUNCTION hstore_to_jsonb(hstore);
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_to_jsonb_loose(hstore)
|
|
|
|
RETURNS jsonb
|
|
|
|
AS 'MODULE_PATHNAME', 'hstore_to_jsonb_loose'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
2011-11-08 10:47:45 +08:00
|
|
|
CREATE FUNCTION hstore(record)
|
|
|
|
RETURNS hstore
|
|
|
|
AS 'MODULE_PATHNAME', 'hstore_from_record'
|
|
|
|
LANGUAGE C IMMUTABLE; -- not STRICT; allows (null::recordtype)
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_to_array(hstore)
|
|
|
|
RETURNS text[]
|
|
|
|
AS 'MODULE_PATHNAME','hstore_to_array'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR %% (
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hstore_to_array
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_to_matrix(hstore)
|
|
|
|
RETURNS text[]
|
|
|
|
AS 'MODULE_PATHNAME','hstore_to_matrix'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR %# (
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hstore_to_matrix
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION akeys(hstore)
|
|
|
|
RETURNS text[]
|
|
|
|
AS 'MODULE_PATHNAME','hstore_akeys'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION avals(hstore)
|
|
|
|
RETURNS text[]
|
|
|
|
AS 'MODULE_PATHNAME','hstore_avals'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION skeys(hstore)
|
|
|
|
RETURNS setof text
|
|
|
|
AS 'MODULE_PATHNAME','hstore_skeys'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION svals(hstore)
|
|
|
|
RETURNS setof text
|
|
|
|
AS 'MODULE_PATHNAME','hstore_svals'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION each(IN hs hstore,
|
|
|
|
OUT key text,
|
|
|
|
OUT value text)
|
|
|
|
RETURNS SETOF record
|
|
|
|
AS 'MODULE_PATHNAME','hstore_each'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION populate_record(anyelement,hstore)
|
|
|
|
RETURNS anyelement
|
|
|
|
AS 'MODULE_PATHNAME', 'hstore_populate_record'
|
|
|
|
LANGUAGE C IMMUTABLE; -- not STRICT; allows (null::rectype,hstore)
|
|
|
|
|
|
|
|
CREATE OPERATOR #= (
|
|
|
|
LEFTARG = anyelement,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = populate_record
|
|
|
|
);
|
|
|
|
|
|
|
|
-- btree support
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_eq(hstore,hstore)
|
|
|
|
RETURNS boolean
|
|
|
|
AS 'MODULE_PATHNAME','hstore_eq'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_ne(hstore,hstore)
|
|
|
|
RETURNS boolean
|
|
|
|
AS 'MODULE_PATHNAME','hstore_ne'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_gt(hstore,hstore)
|
|
|
|
RETURNS boolean
|
|
|
|
AS 'MODULE_PATHNAME','hstore_gt'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_ge(hstore,hstore)
|
|
|
|
RETURNS boolean
|
|
|
|
AS 'MODULE_PATHNAME','hstore_ge'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_lt(hstore,hstore)
|
|
|
|
RETURNS boolean
|
|
|
|
AS 'MODULE_PATHNAME','hstore_lt'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_le(hstore,hstore)
|
|
|
|
RETURNS boolean
|
|
|
|
AS 'MODULE_PATHNAME','hstore_le'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_cmp(hstore,hstore)
|
|
|
|
RETURNS integer
|
|
|
|
AS 'MODULE_PATHNAME','hstore_cmp'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR = (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hstore_eq,
|
|
|
|
COMMUTATOR = =,
|
|
|
|
NEGATOR = <>,
|
|
|
|
RESTRICT = eqsel,
|
|
|
|
JOIN = eqjoinsel,
|
|
|
|
MERGES,
|
|
|
|
HASHES
|
|
|
|
);
|
|
|
|
CREATE OPERATOR <> (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hstore_ne,
|
|
|
|
COMMUTATOR = <>,
|
|
|
|
NEGATOR = =,
|
|
|
|
RESTRICT = neqsel,
|
|
|
|
JOIN = neqjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
-- the comparison operators have funky names (and are undocumented)
|
|
|
|
-- in an attempt to discourage anyone from actually using them. they
|
|
|
|
-- only exist to support the btree opclass
|
|
|
|
|
|
|
|
CREATE OPERATOR #<# (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hstore_lt,
|
|
|
|
COMMUTATOR = #>#,
|
|
|
|
NEGATOR = #>=#,
|
|
|
|
RESTRICT = scalarltsel,
|
|
|
|
JOIN = scalarltjoinsel
|
|
|
|
);
|
|
|
|
CREATE OPERATOR #<=# (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hstore_le,
|
|
|
|
COMMUTATOR = #>=#,
|
|
|
|
NEGATOR = #>#,
|
|
|
|
RESTRICT = scalarltsel,
|
|
|
|
JOIN = scalarltjoinsel
|
|
|
|
);
|
|
|
|
CREATE OPERATOR #># (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hstore_gt,
|
|
|
|
COMMUTATOR = #<#,
|
|
|
|
NEGATOR = #<=#,
|
|
|
|
RESTRICT = scalargtsel,
|
|
|
|
JOIN = scalargtjoinsel
|
|
|
|
);
|
|
|
|
CREATE OPERATOR #>=# (
|
|
|
|
LEFTARG = hstore,
|
|
|
|
RIGHTARG = hstore,
|
|
|
|
PROCEDURE = hstore_ge,
|
|
|
|
COMMUTATOR = #<=#,
|
|
|
|
NEGATOR = #<#,
|
|
|
|
RESTRICT = scalargtsel,
|
|
|
|
JOIN = scalargtjoinsel
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE OPERATOR CLASS btree_hstore_ops
|
|
|
|
DEFAULT FOR TYPE hstore USING btree
|
|
|
|
AS
|
|
|
|
OPERATOR 1 #<# ,
|
|
|
|
OPERATOR 2 #<=# ,
|
|
|
|
OPERATOR 3 = ,
|
|
|
|
OPERATOR 4 #>=# ,
|
|
|
|
OPERATOR 5 #># ,
|
|
|
|
FUNCTION 1 hstore_cmp(hstore,hstore);
|
|
|
|
|
|
|
|
-- hash support
|
|
|
|
|
|
|
|
CREATE FUNCTION hstore_hash(hstore)
|
|
|
|
RETURNS integer
|
|
|
|
AS 'MODULE_PATHNAME','hstore_hash'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE OPERATOR CLASS hash_hstore_ops
|
|
|
|
DEFAULT FOR TYPE hstore USING hash
|
|
|
|
AS
|
|
|
|
OPERATOR 1 = ,
|
|
|
|
FUNCTION 1 hstore_hash(hstore);
|
|
|
|
|
|
|
|
-- GiST support
|
|
|
|
|
|
|
|
CREATE TYPE ghstore;
|
|
|
|
|
|
|
|
CREATE FUNCTION ghstore_in(cstring)
|
|
|
|
RETURNS ghstore
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION ghstore_out(ghstore)
|
|
|
|
RETURNS cstring
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
|
|
|
|
CREATE TYPE ghstore (
|
|
|
|
INTERNALLENGTH = -1,
|
|
|
|
INPUT = ghstore_in,
|
|
|
|
OUTPUT = ghstore_out
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION ghstore_compress(internal)
|
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
CREATE FUNCTION ghstore_decompress(internal)
|
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
CREATE FUNCTION ghstore_penalty(internal,internal,internal)
|
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
CREATE FUNCTION ghstore_picksplit(internal, internal)
|
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
CREATE FUNCTION ghstore_union(internal, internal)
|
Fix assorted inconsistencies in GiST opclass support function declarations.
The conventions specified by the GiST SGML documentation were widely
ignored. For example, the strategy-number argument for "consistent" and
"distance" functions is specified to be a smallint, but most of the
built-in support functions declared it as an integer, and for that matter
the core code passed it using Int32GetDatum not Int16GetDatum. None of
that makes any real difference at runtime, but it's quite confusing for
newcomers to the code, and it makes it very hard to write an amvalidate()
function that checks support function signatures. So let's try to instill
some consistency here.
Another similar issue is that the "query" argument is not of a single
well-defined type, but could have different types depending on the strategy
(corresponding to search operators with different righthand-side argument
types). Some of the functions threw up their hands and declared the query
argument as being of "internal" type, which surely isn't right ("any" would
have been more appropriate); but the majority position seemed to be to
declare it as being of the indexed data type, corresponding to a search
operator with both input types the same. So I've specified a convention
that that's what to do always.
Also, the result of the "union" support function actually must be of the
index's storage type, but the documentation suggested declaring it to
return "internal", and some of the functions followed that. Standardize
on telling the truth, instead.
Similarly, standardize on declaring the "same" function's inputs as
being of the storage type, not "internal".
Also, somebody had forgotten to add the "recheck" argument to both
the documentation of the "distance" support function and all of their
SQL declarations, even though the C code was happily using that argument.
Clean that up too.
Fix up some other omissions in the docs too, such as documenting that
union's second input argument is vestigial.
So far as the errors in core function declarations go, we can just fix
pg_proc.h and bump catversion. Adjusting the erroneous declarations in
contrib modules is more debatable: in principle any change in those
scripts should involve an extension version bump, which is a pain.
However, since these changes are purely cosmetic and make no functional
difference, I think we can get away without doing that.
2016-01-20 01:04:32 +08:00
|
|
|
RETURNS ghstore
|
2011-11-08 10:47:45 +08:00
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
Fix assorted inconsistencies in GiST opclass support function declarations.
The conventions specified by the GiST SGML documentation were widely
ignored. For example, the strategy-number argument for "consistent" and
"distance" functions is specified to be a smallint, but most of the
built-in support functions declared it as an integer, and for that matter
the core code passed it using Int32GetDatum not Int16GetDatum. None of
that makes any real difference at runtime, but it's quite confusing for
newcomers to the code, and it makes it very hard to write an amvalidate()
function that checks support function signatures. So let's try to instill
some consistency here.
Another similar issue is that the "query" argument is not of a single
well-defined type, but could have different types depending on the strategy
(corresponding to search operators with different righthand-side argument
types). Some of the functions threw up their hands and declared the query
argument as being of "internal" type, which surely isn't right ("any" would
have been more appropriate); but the majority position seemed to be to
declare it as being of the indexed data type, corresponding to a search
operator with both input types the same. So I've specified a convention
that that's what to do always.
Also, the result of the "union" support function actually must be of the
index's storage type, but the documentation suggested declaring it to
return "internal", and some of the functions followed that. Standardize
on telling the truth, instead.
Similarly, standardize on declaring the "same" function's inputs as
being of the storage type, not "internal".
Also, somebody had forgotten to add the "recheck" argument to both
the documentation of the "distance" support function and all of their
SQL declarations, even though the C code was happily using that argument.
Clean that up too.
Fix up some other omissions in the docs too, such as documenting that
union's second input argument is vestigial.
So far as the errors in core function declarations go, we can just fix
pg_proc.h and bump catversion. Adjusting the erroneous declarations in
contrib modules is more debatable: in principle any change in those
scripts should involve an extension version bump, which is a pain.
However, since these changes are purely cosmetic and make no functional
difference, I think we can get away without doing that.
2016-01-20 01:04:32 +08:00
|
|
|
CREATE FUNCTION ghstore_same(ghstore, ghstore, internal)
|
2011-11-08 10:47:45 +08:00
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
Fix assorted inconsistencies in GiST opclass support function declarations.
The conventions specified by the GiST SGML documentation were widely
ignored. For example, the strategy-number argument for "consistent" and
"distance" functions is specified to be a smallint, but most of the
built-in support functions declared it as an integer, and for that matter
the core code passed it using Int32GetDatum not Int16GetDatum. None of
that makes any real difference at runtime, but it's quite confusing for
newcomers to the code, and it makes it very hard to write an amvalidate()
function that checks support function signatures. So let's try to instill
some consistency here.
Another similar issue is that the "query" argument is not of a single
well-defined type, but could have different types depending on the strategy
(corresponding to search operators with different righthand-side argument
types). Some of the functions threw up their hands and declared the query
argument as being of "internal" type, which surely isn't right ("any" would
have been more appropriate); but the majority position seemed to be to
declare it as being of the indexed data type, corresponding to a search
operator with both input types the same. So I've specified a convention
that that's what to do always.
Also, the result of the "union" support function actually must be of the
index's storage type, but the documentation suggested declaring it to
return "internal", and some of the functions followed that. Standardize
on telling the truth, instead.
Similarly, standardize on declaring the "same" function's inputs as
being of the storage type, not "internal".
Also, somebody had forgotten to add the "recheck" argument to both
the documentation of the "distance" support function and all of their
SQL declarations, even though the C code was happily using that argument.
Clean that up too.
Fix up some other omissions in the docs too, such as documenting that
union's second input argument is vestigial.
So far as the errors in core function declarations go, we can just fix
pg_proc.h and bump catversion. Adjusting the erroneous declarations in
contrib modules is more debatable: in principle any change in those
scripts should involve an extension version bump, which is a pain.
However, since these changes are purely cosmetic and make no functional
difference, I think we can get away without doing that.
2016-01-20 01:04:32 +08:00
|
|
|
CREATE FUNCTION ghstore_consistent(internal,hstore,smallint,oid,internal)
|
2011-11-08 10:47:45 +08:00
|
|
|
RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
CREATE OPERATOR CLASS gist_hstore_ops
|
|
|
|
DEFAULT FOR TYPE hstore USING gist
|
|
|
|
AS
|
|
|
|
OPERATOR 7 @> ,
|
|
|
|
OPERATOR 9 ?(hstore,text) ,
|
|
|
|
OPERATOR 10 ?|(hstore,text[]) ,
|
|
|
|
OPERATOR 11 ?&(hstore,text[]) ,
|
|
|
|
--OPERATOR 8 <@ ,
|
|
|
|
OPERATOR 13 @ ,
|
|
|
|
--OPERATOR 14 ~ ,
|
Fix assorted inconsistencies in GiST opclass support function declarations.
The conventions specified by the GiST SGML documentation were widely
ignored. For example, the strategy-number argument for "consistent" and
"distance" functions is specified to be a smallint, but most of the
built-in support functions declared it as an integer, and for that matter
the core code passed it using Int32GetDatum not Int16GetDatum. None of
that makes any real difference at runtime, but it's quite confusing for
newcomers to the code, and it makes it very hard to write an amvalidate()
function that checks support function signatures. So let's try to instill
some consistency here.
Another similar issue is that the "query" argument is not of a single
well-defined type, but could have different types depending on the strategy
(corresponding to search operators with different righthand-side argument
types). Some of the functions threw up their hands and declared the query
argument as being of "internal" type, which surely isn't right ("any" would
have been more appropriate); but the majority position seemed to be to
declare it as being of the indexed data type, corresponding to a search
operator with both input types the same. So I've specified a convention
that that's what to do always.
Also, the result of the "union" support function actually must be of the
index's storage type, but the documentation suggested declaring it to
return "internal", and some of the functions followed that. Standardize
on telling the truth, instead.
Similarly, standardize on declaring the "same" function's inputs as
being of the storage type, not "internal".
Also, somebody had forgotten to add the "recheck" argument to both
the documentation of the "distance" support function and all of their
SQL declarations, even though the C code was happily using that argument.
Clean that up too.
Fix up some other omissions in the docs too, such as documenting that
union's second input argument is vestigial.
So far as the errors in core function declarations go, we can just fix
pg_proc.h and bump catversion. Adjusting the erroneous declarations in
contrib modules is more debatable: in principle any change in those
scripts should involve an extension version bump, which is a pain.
However, since these changes are purely cosmetic and make no functional
difference, I think we can get away without doing that.
2016-01-20 01:04:32 +08:00
|
|
|
FUNCTION 1 ghstore_consistent (internal, hstore, smallint, oid, internal),
|
2011-11-08 10:47:45 +08:00
|
|
|
FUNCTION 2 ghstore_union (internal, internal),
|
|
|
|
FUNCTION 3 ghstore_compress (internal),
|
|
|
|
FUNCTION 4 ghstore_decompress (internal),
|
|
|
|
FUNCTION 5 ghstore_penalty (internal, internal, internal),
|
|
|
|
FUNCTION 6 ghstore_picksplit (internal, internal),
|
Fix assorted inconsistencies in GiST opclass support function declarations.
The conventions specified by the GiST SGML documentation were widely
ignored. For example, the strategy-number argument for "consistent" and
"distance" functions is specified to be a smallint, but most of the
built-in support functions declared it as an integer, and for that matter
the core code passed it using Int32GetDatum not Int16GetDatum. None of
that makes any real difference at runtime, but it's quite confusing for
newcomers to the code, and it makes it very hard to write an amvalidate()
function that checks support function signatures. So let's try to instill
some consistency here.
Another similar issue is that the "query" argument is not of a single
well-defined type, but could have different types depending on the strategy
(corresponding to search operators with different righthand-side argument
types). Some of the functions threw up their hands and declared the query
argument as being of "internal" type, which surely isn't right ("any" would
have been more appropriate); but the majority position seemed to be to
declare it as being of the indexed data type, corresponding to a search
operator with both input types the same. So I've specified a convention
that that's what to do always.
Also, the result of the "union" support function actually must be of the
index's storage type, but the documentation suggested declaring it to
return "internal", and some of the functions followed that. Standardize
on telling the truth, instead.
Similarly, standardize on declaring the "same" function's inputs as
being of the storage type, not "internal".
Also, somebody had forgotten to add the "recheck" argument to both
the documentation of the "distance" support function and all of their
SQL declarations, even though the C code was happily using that argument.
Clean that up too.
Fix up some other omissions in the docs too, such as documenting that
union's second input argument is vestigial.
So far as the errors in core function declarations go, we can just fix
pg_proc.h and bump catversion. Adjusting the erroneous declarations in
contrib modules is more debatable: in principle any change in those
scripts should involve an extension version bump, which is a pain.
However, since these changes are purely cosmetic and make no functional
difference, I think we can get away without doing that.
2016-01-20 01:04:32 +08:00
|
|
|
FUNCTION 7 ghstore_same (ghstore, ghstore, internal),
|
2011-11-08 10:47:45 +08:00
|
|
|
STORAGE ghstore;
|
|
|
|
|
|
|
|
-- GIN support
|
|
|
|
|
2016-01-20 11:32:19 +08:00
|
|
|
CREATE FUNCTION gin_extract_hstore(hstore, internal)
|
2011-11-08 10:47:45 +08:00
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
2016-01-20 11:32:19 +08:00
|
|
|
CREATE FUNCTION gin_extract_hstore_query(hstore, internal, int2, internal, internal)
|
2011-11-08 10:47:45 +08:00
|
|
|
RETURNS internal
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
2016-01-20 11:32:19 +08:00
|
|
|
CREATE FUNCTION gin_consistent_hstore(internal, int2, hstore, int4, internal, internal)
|
2011-11-08 10:47:45 +08:00
|
|
|
RETURNS bool
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
|
|
|
|
|
|
|
CREATE OPERATOR CLASS gin_hstore_ops
|
|
|
|
DEFAULT FOR TYPE hstore USING gin
|
|
|
|
AS
|
|
|
|
OPERATOR 7 @>,
|
|
|
|
OPERATOR 9 ?(hstore,text),
|
|
|
|
OPERATOR 10 ?|(hstore,text[]),
|
|
|
|
OPERATOR 11 ?&(hstore,text[]),
|
|
|
|
FUNCTION 1 bttextcmp(text,text),
|
2016-01-20 11:32:19 +08:00
|
|
|
FUNCTION 2 gin_extract_hstore(hstore, internal),
|
|
|
|
FUNCTION 3 gin_extract_hstore_query(hstore, internal, int2, internal, internal),
|
|
|
|
FUNCTION 4 gin_consistent_hstore(internal, int2, hstore, int4, internal, internal),
|
2011-11-08 10:47:45 +08:00
|
|
|
STORAGE text;
|