5 ms·
> I am actually pretty excited about the native JSON support There really isn't much to it yet, it's basically a varchar field with JSON validation, it's not l
by masklinn 14y ago
> I am actually pretty excited about the native JSON support
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`)
- StavrosK 14y agoEh, if you want to index it you have the hstore. I do wonder why they don't deserialize to an hstore type, though.
- pilif 14y agoI'm sure something like that will be added. One of the issues there facing is that hstore is a string => string map, so a conversion from json to that will be lossy (i.e. 'that "true" in hstore, is that the string "true" or a converted boolean true from json?'). 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.
- masklinn 14y ago> One of the issues there facing is that hstore is a string => string map, so a conversion from json to that will be lossy Or the insertion/conversion routine can assert that the JSON object is a string:string mapping only.
- joevandyk 14y agoWhy would that be helpful? I'd want arrays, hashes, integers, etc.
- masklinn 14y agoYou won't get them in an hstore[0] column, which was the context of my reply. Of course in a JSON column you want full JSON support, but my and my parent's post were about converting back and forth between hstore and json. Since hstore only handles string:string mapping, the choice is either to silently corrupt data by stringifying all values in the json->hstore encoding, or erroring out if the input data is anything other than string:string. The latter would be what I'd prefer, and more in line with usual Postgres behavior. [0] http://www.postgresql.org/docs/9.2/static/hstore.html http://www.postgresql.org/docs/9.2/static/hstore.html
- wisty 14y agoJSON isn't much like hstore, as JSON can be recursive. I don't think hstore can. Still, there's no reason why you couldn't write a function to index JSON however you like.
- jahewson 14y agoA hstore field can only contain strings, so it's not a one-size-fits-all indexing solution in this case.
- masklinn 14y agohstore is much more limited, it's a flat mapping of strings to strings (so a single level of JSON object). And as I noted, there does not seem to be any convenience method for converting between hstore and JSON data (or the other way around)
- hgimenez 14y agoJSON is much more powerful than hstore. Not only can it store different JSON data types (boolean, numbers) but also you can store documents with multiple levels deep, which is not possible on the hstore type. 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.
- porlw 14y agoI think you can index JSON using a function based index, which will probably cover a lot of use-cases.
- einhverfr 14y agoIn addition, I don't know what you'd index if it wasn't through a function. Indexing JSON data as JSON? Why?
- joevandyk 14y agoYou can query and index json columns using plv8. http://lanyrd.com/coverage/?speakers=leinweber&topics=json http://lanyrd.com/coverage/?speakers=leinweber&topics=js... has more details.
- jaylevitt 14y agoAs one of the main contribs noted in a previous HN article, the important part was to get JSON conversion into core, full stop - because extensions (like hstore) can't declare dependencies on other extensions. Having JSON in/out in core is an enabling feature for all the rest.
- fdr 14y agoThat limitation (not-lucid dependencies between contribs) is rather sucky, but jumping into the world of dependency management will require a deep breath for sure. 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.