F.10. hstore

The hstore module is usefull for storing (key,value) pairs. This module can be useful in different scenarios: case with many attributes rarely searched, semistructural data or a lazy DBA.

F.10.1. Operations

F.10.2. Functions

F.10.3. Indices

Module provides index support for '@>' and '?' operations.

CREATE INDEX hidx ON testhstore USING GIST(h);
CREATE INDEX hidx ON testhstore USING GIN(h);
  

F.10.4. Examples

Add a key:

UPDATE tt SET h=h||'c=>3';
  

Delete a key:

UPDATE tt SET h=delete(h,'k1');
  

F.10.5. Statistics

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.

Simple example

SELECT * FROM each('aaa=>bq, b=>NULL, ""=>1 ');
  

Using table

SELECT (each(h)).key, (each(h)).value INTO stat FROM testhstore ;
  

Online stat

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
...................
  

F.10.6. Authors

Oleg Bartunov , Moscow, Moscow University, Russia

Teodor Sigaev , Moscow, Delta-Soft Ltd.,Russia