PostgreSQL just introduced JSONB and it's already trending on hacker news. How is it different from Hstore and JSON previously present in PostgreSQL?
What are its advantages and limitations and when should someone consider using it?
jsonjsonbnosqlpostgresqlpostgresql-json
PostgreSQL just introduced JSONB and it's already trending on hacker news. How is it different from Hstore and JSON previously present in PostgreSQL?
What are its advantages and limitations and when should someone consider using it?
Best Answer
First,
hstore
is a contrib module, which only allows you to store key => value pairs, where keys and values can only betext
s (however values can be sqlNULL
s too).Both
json
&jsonb
allows you to store a valid JSON value (defined in its spec).F.ex. these are valid JSON representations:
null
,true
,[1,false,"string",{"foo":"bar"}]
,{"foo":"bar","baz":[null]}
-hstore
is just a little subset compared to what JSON is capable (but if you only need this subset, it's fine).The only difference between
json
&jsonb
is their storage:json
is stored in its plain text format, whilejsonb
is stored in some binary representationThere are 3 major consequences of this:
jsonb
usually takes more disk space to store thanjson
(sometimes not)jsonb
takes more time to build from its input representation thanjson
json
operations take significantly more time thanjsonb
(& parsing also needs to be done each time you do some operation at ajson
typed value)When
jsonb
will be available with a stable release, there will be two major use cases, when you can easily select between them:json
.jsonb
.