Documentazione di PostgreSQL 9.0 > Appendici > Additional Supplied Modules > btree_gist
Precedentebtree_ginchkpassSuccessivo

F.4. btree_gist

btree_gist provides sample gist operator classes that implement B-tree equivalent behavior for the data types int2, int4, int8, float4, float8, numeric, timestamp with time zone, timestamp without time zone, time with time zone, time without time zone, date, interval, oid, money, char, varchar, text, bytea, bit, varbit, macaddr, inet, and cidr.

In general, these operator classes will not outperform the equivalent standard B-tree index methods, and they lack one major feature of the standard B-tree code: the ability to enforce uniqueness. However, they are useful for gist testing and as a base for developing other gist operator classes.

In addition to the typical btree search operators, btree_gist also provides search operators for <>not equals»). This may be useful in combination with an exclusion constraint, as described below.

F.4.1. Example usage

Simple example using btree_gist instead of btree:

CREATE TABLE test (a int4);
-- create index
CREATE INDEX testidx ON test USING gist (a);
-- query
SELECT * FROM test WHERE a < 10;

Use an exclusion constraint to enforce the rule that a cage at a zoo can contain only one kind of animal:

=> CREATE TABLE zoo (
  cage   INTEGER,
  animal TEXT,
  EXCLUDE USING gist (cage WITH =, animal WITH <>)
);

=> INSERT INTO zoo VALUES(123, 'zebra');
INSERT 0 1
=> INSERT INTO zoo VALUES(123, 'zebra');
INSERT 0 1
=> INSERT INTO zoo VALUES(123, 'lion');
ERROR:  conflicting key value violates exclusion constraint "zoo_cage_animal_excl"
DETAIL:  Key (cage, animal)=(123, lion) conflicts with existing key (cage, animal)=(123, zebra).
=> INSERT INTO zoo VALUES(124, 'lion');
INSERT 0 1

F.4.2. Authors

Teodor Sigaev () , Oleg Bartunov (), and Janko Richter (). See http://www.sai.msu.su/~megera/postgres/gist/ for additional information.

Documentazione di PostgreSQL 9.0 > Appendici > Additional Supplied Modules > btree_gist
Precedentebtree_ginchkpassSuccessivo