1 Hstore - contrib module for storing (key,value) pairs
3 [Online version] (http://www.sai.msu.su/~megera/oddmuse/index.cgi?Hstore)
7 Many attributes rarely searched, semistructural data, lazy DBA
11 * Oleg Bartunov <oleg@sai.msu.su>, Moscow, Moscow University, Russia
12 * Teodor Sigaev <teodor@sigaev.ru>, Moscow, Delta-Soft Ltd.,Russia
16 Stable version, included into PostgreSQL distribution, released under BSD license. Development version, available from this site, released under the GNU General Public License, version 2 (June 1991).
20 * hstore -> text - get value , perl analogy $h{key}
22 select 'a=>q, b=>g'->'a';
27 * hstore || hstore - concatenation, perl analogy %a=( %b, %c );
29 regression=# select 'a=>b'::hstore || 'c=>d'::hstore;
37 regression=# select 'a=>b'::hstore || 'a=>d'::hstore;
43 * text => text - creates hstore type from two text strings
50 * hstore @ hstore - contains operation, check if left operand contains right.
52 regression=# select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>c';
58 regression=# select 'a=>b, b=>1, c=>NULL'::hstore @ 'b=>1';
64 * hstore ~ hstore - contained operation, check if left operand is contained in right
68 * akeys(hstore) - returns all keys from hstore as array
70 regression=# select akeys('a=>1,b=>2');
75 * skeys(hstore) - returns all keys from hstore as strings
77 regression=# select skeys('a=>1,b=>2');
83 * avals(hstore) - returns all values from hstore as array
85 regression=# select avals('a=>1,b=>2');
90 * svals(hstore) - returns all values from hstore as strings
92 regression=# select svals('a=>1,b=>2');
98 * delete (hstore,text) - delete (key,value) from hstore if key matches argument.
100 regression=# select delete('a=>1,b=>2','b');
105 * each(hstore) return (key, value) pairs
107 regression=# select * from each('a=>1,b=>2');
113 * isexists (hstore,text) - returns 'true if key is exists in hstore and false otherwise.
115 regression=# select isexists('a=>1','a');
120 * isdefined (hstore,text) - returns true if key is exists in hstore and its value is not NULL.
122 regression=# select isdefined('a=>NULL','a');
129 Module provides index support for '@' and '~' operations.
131 create index hidx on testhstore using gist(h);
135 Use parenthesis in select below, because priority of 'is' is higher than that of '->'
137 select id from entrants where (info->'education_period') is not null;
143 update tt set h=h||'c=>3';
147 update tt set h=delete(h,'k1');
151 hstore type, because of its intrinsic liberality, could contain a lot of different keys. Checking for valid keys is the task of application. Examples below demonstrate several techniques how to check keys statistics.
155 select * from each('aaa=>bq, b=>NULL, ""=>1 ');
159 select (each(h)).key, (each(h)).value into stat from testhstore ;
163 select key, count(*) from (select (each(h)).key from testhstore) as stat group by key order by count desc, key;