// data type reference

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.

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.

Hstore in SQL Server, PostgreSQL, MySQL, SQLite and Oracle: type name, storage and notes
引擎 類型 儲存 備註
SQL Server none (JSON workaround) Workaround 不適用 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 不適用 No equivalent. JSON columns cover key-value access; SET columns exist but hold enumerated values, not arbitrary keys.
SQLite none (TEXT workaround) Workaround 不適用 No equivalent. JSON (JSON1 functions) or a key-value child table is the pattern.
Oracle none (JSON workaround) Workaround 不適用 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.

  1. 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.
  2. 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').
  3. 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.
  4. 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.
  5. 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').

// map types before you move data

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.