Hstore: key-value storage
hstore is PostgreSQL's original key-value column: a flat map of text to text, indexable with GIN. JSONB does most of its job now, and the other engines never had a name for it at all.
- Family
- JSON & semi-structured
- Missing in
- SQL Server, MySQL, SQLite, Oracle
- Gotchas
- 5 listed
Engine by engine
hstore is a PostgreSQL extension for flat string-to-string maps, GIN-indexable and cheap. jsonb supersedes it for nested data; every other engine reaches for JSON or a child table.
| Motor | Tipo | Armazenamento | Notas |
|---|---|---|---|
| SQL Server |
none (JSON workaround)
Workaround
|
n/a | No key-value type. NVARCHAR(MAX) JSON with OPENJSON, or an EAV child table for attribute-heavy designs. |
| PostgreSQL |
HSTORE
|
Text pairs, variable | Extension (CREATE EXTENSION hstore): flat text-to-text map written 'a=>1, b=>2', with operators ->, ?, ?|, ?& and @>; GIN indexes serve key and containment lookups. |
| MySQL |
none (JSON workaround)
Workaround
|
n/a | No equivalent. JSON columns cover key-value access; SET columns exist but hold enumerated values, not arbitrary keys. |
| SQLite |
none (TEXT workaround)
Workaround
|
n/a | No equivalent. JSON (JSON1 functions) or a key-value child table is the pattern. |
| Oracle |
none (JSON workaround)
Workaround
|
n/a | No hstore; use native JSON columns (21c+) or a name/value child table. Oracle's object types can fake maps but are not queryable the same way. |
Gotchas
Where the engines disagree. These tend to surface as bugs during a migration or a port.
- hstore values are text, full stop: storing numbers and booleans works, but every read compares and sorts strings, and there are no nested structures. jsonb keeps types and nests.
- hstore keeps one value per key, and when the input repeats a key the docs do not promise which value survives. Old code that builds values with the text => text operator breaks: that operator was removed; use hstore('k', 'v').
- GIN index choice matters for both: the default jsonb_ops class indexes every key and value, while jsonb_path_ops is smaller but only serves @>. Measure index size before indexing a wide attribute column.
- The other four engines have no hstore, so any schema using it needs a documented JSON or EAV translation for migrations, not a type mapping.
- For flat user-defined attributes, hstore's text-only model is a fine fit, and existing hstore columns convert to jsonb with a plain cast (col::jsonb) when nesting or types become necessary.
Common questions
Is hstore deprecated in favor of jsonb?
Not deprecated, just niche. It still ships with PostgreSQL and works well for flat text-to-text maps; for anything nested or typed, jsonb wins. New schemas usually default to jsonb.
Why do I get 'type hstore does not exist'?
hstore ships with PostgreSQL as a contrib extension, so each database needs CREATE EXTENSION hstore before the type exists. Most managed services allow it; locked-down installs may not.
How do I query 'has this key' in hstore?
Use the ? operator (attr ? 'color') or @> for containment (attr @> 'color=>red'), both GIN-indexable. To build a value in code, call hstore('color', 'red').
Related on SQLly
Map a type to the other four engines
The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.