Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Eh, if you want to index it you have the hstore. I do wonder why they don't deserialize to an hstore type, though.


I'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.


> 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.


Why would that be helpful? I'd want arrays, hashes, integers, etc.


You 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


JSON 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.


JSON 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.


hstore 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)


A hstore field can only contain strings, so it's not a one-size-fits-all indexing solution in this case.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: