用于存储键值映射的最佳PostgreSQL数据类型?

编程入门 行业动态 更新时间:2024-10-28 15:19:12
本文介绍了用于存储键值映射的最佳PostgreSQL数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将一个简单的键值字符串映射存储为我的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数据类型?

本文发布于:2023-10-28 01:58:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535164.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:键值   数据类型   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!