为Postgresql生成hstore值

为Postgresql生成hstore值,postgresql,rspec,sequel,hstore,fabrication-gem,Postgresql,Rspec,Sequel,Hstore,Fabrication Gem,正如在标题中一样,我尝试将散列编入hstore类型列 我已经看到了这个问题,但那个解决方案对我不起作用 我的hstore列名是“status”,我想在那里设置三个标志:“processed”、“duplicate”、“eol”。我使用sequel(4.14.0)作为ORM,制作(2.8.1),Ruby 2.1.2,当然还有Postgresql;) 案例1: status {eol: true, duplicate: false, processed: true} status {"heol"=

正如在标题中一样,我尝试将散列编入hstore类型列

我已经看到了这个问题,但那个解决方案对我不起作用

我的hstore列名是“status”,我想在那里设置三个标志:“processed”、“duplicate”、“eol”。我使用sequel(4.14.0)作为ORM,制作(2.8.1),Ruby 2.1.2,当然还有Postgresql;)

案例1:

status {eol: true, duplicate: false, processed: true}
status {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
  status do
    {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
  end
status do
    {status: "heol:true"}
  end
结果:

语法错误

案例2:

status {eol: true, duplicate: false, processed: true}
status {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
  status do
    {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
  end
status do
    {status: "heol:true"}
  end
结果:

语法错误

案例3:

status {eol: true, duplicate: false, processed: true}
status {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
  status do
    {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
  end
status do
    {status: "heol:true"}
  end
结果:

Sequel::数据库错误: PG::DatatypeMismatch:错误:“status”列的类型为hstore,但表达式的类型为boolean 第1行:…23.0,'2000-01-01',('heol'='。。。 提示:您需要重写或强制转换表达式

案例4:

status {eol: true, duplicate: false, processed: true}
status {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
  status do
    {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
  end
status do
    {status: "heol:true"}
  end
结果:

失败/错误:制造(:输入) Sequel::数据库错误: PG::UndefinedColumn:错误:列“状态”不存在 第1行:…123.0,'2000-01-01',(“状态”=。。。 提示:表“entries”中有一个名为“status”的列,但不能从查询的这一部分引用它

案例5:

status {eol: true, duplicate: false, processed: true}
status {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
  status do
    {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
  end
status do
    {status: "heol:true"}
  end
地位 {'status'=>“heol:true”}结束

结果:

案例6: 放弃;) 结果: 这个问题

对于FactoryGirl,一切都按预期进行,语法也很简单:

FactoryGirl.define do
  factory :entry do
    status {{ flag_processed: true, flag_duplicate: false }}
end
承诺在制作过程中充分使用正确的语法=) 谢谢


Lucas。

案例1和案例2肯定不是您想要的。哈希需要在块中指定,这与FactoryGirl对包含双大括号的示例所做的相同。案例3、4和5通常可以工作,但不能工作,因为Sequel具有指定hstore列的特殊语法,并且不会自动生成为你翻译它(因为在你提到它之前,我不知道这是一件事)

如果你改成这样,我想你会成功的:

status do
  Sequel.hstore("heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true")
end

请注意:要使用Sequel.hstore方法,您需要在数据库实例(DB:DB.extension:pg_hstore)上启用Sequel的pg_hstore扩展