History:
Many attributes rarely searched, semistructural data, lazy DBA
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).
select 'a=>q, b=>g'->'a'; ? ------ q
regression=# select 'a=>b'::hstore || 'c=>d'::hstore; ?column? -------------------- "a"=>"b", "c"=>"d" (1 row)
but, notice
regression=# select 'a=>b'::hstore || 'a=>d'::hstore; ?column? ---------- "a"=>"d" (1 row)
select 'a'=>'b'; ?column? ---------- "a"=>"b"
regression=# select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>c'; ?column? ---------- f (1 row) regression=# select 'a=>b, b=>1, c=>NULL'::hstore @ 'b=>1'; ?column? ---------- t (1 row)
regression=# select akeys('a=>1,b=>2'); akeys ------- {a,b}
regression=# select skeys('a=>1,b=>2'); skeys ------- a b
regression=# select avals('a=>1,b=>2'); avals ------- {1,2}
regression=# select svals('a=>1,b=>2'); svals ------- 1 2
regression=# select delete('a=>1,b=>2','b'); delete ---------- "a"=>"1"
regression=# select * from each('a=>1,b=>2'); key | value -----+------- a | 1 b | 2
regression=# select exist('a=>1','a'); exists ---------- t
regression=# select defined('a=>NULL','a'); defined ----------- f
Module provides index support for '@' and '~' operations.
create index hidx on testhstore using gist(h);
Use parenthesis in select below, because priority of 'is' is higher than that of '->'
select id from entrants where (info->'education_period') is not null;
update tt set h=h||'c=>3';
update tt set h=delete(h,'k1');
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.
select * from each('aaa=>bq, b=>NULL, ""=>1 ');
select (each(h)).key, (each(h)).value into stat from testhstore ;
select key, count(*) from (select (each(h)).key from testhstore) as stat group by key order by count desc, key; key | count -----------+------- line | 883 query | 207 pos | 203 node | 202 space | 197 status | 195 public | 194 title | 190 org | 189 ...................