我想将一个简单的键值字符串映射存储为我的PostgreSQL表中的一个字段.我打算将地图作为一个整体来对待;即,始终选择整个地图,永远不要通过其键或值进行查询.
I'd like to store a simple map of key-value strings as a field in my PostgreSQL table. I intend to treat the map as a whole; i.e, always select the entire map, and never query by its keys nor values.
我已经阅读了hstore,json和jsonb之间进行比较的文章,但是这些并没有帮助我选择最适合我的需求的数据类型,即:
I've read articles comparing between hstore, json and jsonb, but those didn't help me choose which data-type is most fitting for my requirements, which are:
- 仅键值,无需嵌套.
- 仅字符串,没有其他类型,也没有null.
- 考虑到我在该领域的预期用途,存储效率.
- 快速解析查询的地图.
- Only key-value, no need for nesting.
- Only strings, no other types nor null.
- Storage efficiency, given my intended use for the field.
- Fast parsing of the queried maps.
哪种数据类型最适合我的用例?
What data-type would best fit my use case?
推荐答案您可以使用hstore这是一个按键映射,但是我个人会使用jsonb.这有点矫kill过正,但是,大多数语言都可以本地转换json,而无需自己解码.
you could use hstore which is a keymap, however I personally would us jsonb. It's a little overkill, however, most languages can convert json natively without having to decode it yourself.
在json中,我只是存储了一个简单的对象或数组,用于存储您要存储的信息.
In json, I'd just store a simple object or array for the info you're trying to store.
这两个支持索引都被有效地存储.
Both support indexes and are efficiently stored.
Hstore in text是一种自定义类型格式,您的语言可能不知道这种格式,因此需要处理数据才能插入或查询.
Hstore in text is a custom type format that your language may be unaware of and thus require processing the data to insert or query.
更多推荐
用于存储键值映射的最佳PostgreSQL数据类型?
发布评论