3 ms·
Please help me understand this better. So HStoreField is not exactly Json field type of postgres but rather a subset of it, i.e just string->string mapping with
by shreyas056 12y ago
Please help me understand this better. So HStoreField is not exactly Json field type of postgres but rather a subset of it, i.e just string->string mapping without any nesting. You cant even have key->array mapping?
- alexhill 12y agoBasically yes. hstore and json have entirely separate interfaces in Postgres, but the storage properties of hstore are a subset of json as you say. json/jsonb is generally more powerful, and will supplant hstore in a lot of new projects. However hstore has been a part of Postgres since version 8.2 released in 2006, and I think was around as a third-party project before that, so it's used by a lot of projects. It's also easier to manipulate hstore values then json values within the database. hstore's simplicity allows operators for combining and subtracting hstore values[0] which json doesn't have. Due to its restrictions, an hstore can also be converted to and from a record type (think database row). JSON fields on the other hand will generally be populated by your app and then only queried by the database. [0] http://www.postgresql.org/docs/9.4/static/hstore.html#HSTORE-OP-TABLE http://www.postgresql.org/docs/9.4/static/hstore.html#HSTORE...
- shreyas056 12y agoThanks for the explanation. So this means that Django does not support JSON or JSONB field types yet
- alexhill 12y agoNot built-in, but there are plenty of third-party JSON fields around. However, the author of contrib.postgres opened this PR yesterday, so you can certainly expect them in the next release: https://github.com/django/django/pull/4427 https://github.com/django/django/pull/4427
- shreyas056 12y agoGreat! this is very helpful