gpt4 book ai didi

ruby-on-rails - 在 postgres 和 rails 中的数组、json 和 hstore 数据类型之间进行选择

转载 作者:行者123 更新时间:2023-11-29 13:22:46 25 4
gpt4 key购买 nike

我有一些与其他字段相关的字段,我认为将其放在一个数据库列中会更清晰。

例如,假设我有这些字段:parking_available:boolean paid_parking:boolean free_parking:boolean parking_price:integerreservation_required:boolean

因此,如果我使用arraysjsonhstore,那么我可以storefetch 上述参数的值按字符串顺序排列,不考虑数据类型。但是我不知道哪个更好,还是坚持使用各个数据库字段。有人可以解释一下 arraysjsonhstore 的用例以及它们的性能优势吗?

最佳答案

虽然,它没有直接回答你的问题,How to persist hashes in rails application with postgresql关于 hstore、JSON 和 JSONB 的说明

Although it may not be a common case to store other types than string in a dictionary, it is still worth to have in mind that hstore supports only string data.

...

it (JSON) supports nested objects and more datatypes. It also has more operators that are very well described in documentation. If you are using JSON somewhere in your application already and want to store it directly in database, then the JSON datatype is perfect choice.

...

If you still wonder whether MongoDB will be better choice for you needs, check JSONB support introduced in 9.4 version of postgres, which is real data type with binary storage and indexing, a structured format for storing json

根据我对上面源码的解释,你应该使用JSON或者JSONB(如果你已经在使用PostgreSQL 9.4+或者没有改变到9.4+的抑制因素)

关于ruby-on-rails - 在 postgres 和 rails 中的数组、json 和 hstore 数据类型之间进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38911172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com