by masklinn · 14y ago · 0 comments
There really isn't much to it yet, it's basically a varchar field with JSON validation, it's not like you can query or index it.
I actually find the `row_to_json` and `array_to_json` functions more interesting for now (though strangely enough there's no `hstore_to_json`)
Hence, instead of waiting for that, JSON support in un-adorned Postgres to solve a common use case in the interceding years.
The jargon for what this gives you is "a stable oid". Also more or less equivalent to a "system OID" at this time. These "Object IDentifiers" in Postgres are unsigned int32s that are (almost?) never reused (only accrued, or removed), and are all under the number 10000, and all assigned statically by hand. A-priori knowledge of these numbers can simplify writing extensions dramatically, but clearly this is not scalable for a future with dependency chains in extensions.
What you can do right now though is use PL/V8 to query the JSON fields. Then you can use functional indexes to still being able to speed up queries. Yes. You could that before but now there's a guarantee that a field of type json contains just that, meaning that your application logic will get simpler.
Or the insertion/conversion routine can assert that the JSON object is a string:string mapping only.
Still, there's no reason why you couldn't write a function to index JSON however you like.
Having said that, hstore is perfect when storing simple key/values. It's been battle tested and used for years and has some powerful and native indexing possibilities.