是否可以在PostgreSQL中拥有一个hstore数组

swa*_*psm 5 postgresql activerecord ruby-on-rails-3 postgresql-9.1

我是PostgreSQL的初学者.我对Postgres提供的hstore数据类型感到非常惊讶.好吧,我正在使用Rails 3框架并开发一个使用PostgreSQL的简单应用程序.我想在一个字段中存储一个哈希数组.例如:

authors: [
           {
             name: "abc",
             email: "abc@example.com"
           },
           {
             name: "xyz",
             email: "xyz@example.com"
           }
         ]
Run Code Online (Sandbox Code Playgroud)

在使用Rails 3的PostgreSQL中这是可能的吗?如果是这样,有人可以提供有关如何的见解吗?

谢谢

ino*_*tus 7

当然可以在Rails 4中创建一个数组的hstore列,例如在表创建中使用这样的列规范:

t.hstore :properties, :array => true
Run Code Online (Sandbox Code Playgroud)

但是,Rails 4.0中存在编码错误,遗憾的是它们无法使用; 基本上你可以从它们读取它们并且它们正确地呈现为散列数组,但不能写入.

我已经在https://github.com/rails/rails/issues/11135上打开了一个问题(修复补丁),希望很快就会合并.