Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用postgresql的高级hstore_Sql_Ruby On Rails_Ruby_Postgresql_Hstore - Fatal编程技术网

使用postgresql的高级hstore

使用postgresql的高级hstore,sql,ruby-on-rails,ruby,postgresql,hstore,Sql,Ruby On Rails,Ruby,Postgresql,Hstore,在我的RubyonRails应用程序中,我有一些sql来检索高级数据,然后我将这些sql输出转换为散列并更新适当的模型记录。在这个sql中,我有这样一行: hstore(array_agg('some_key'::text), array_agg('some_value'::text)) as loaded_user_data 将其转换为散列后返回给我: "loaded_user_data"=>"\"some_key\"=>\"some_value\"" 但问题是我想让这个散

在我的RubyonRails应用程序中,我有一些sql来检索高级数据,然后我将这些sql输出转换为散列并更新适当的模型记录。在这个sql中,我有这样一行:

hstore(array_agg('some_key'::text), array_agg('some_value'::text)) as  loaded_user_data
将其转换为散列后返回给我:

 "loaded_user_data"=>"\"some_key\"=>\"some_value\""
但问题是我想让这个散列看起来有点不同。例如:

 loaded_user_data: {
    loaded: { count:  100, details: [] },
    failed: { count: 2, details: ['duplicate', 'invalid_external_id']},
    invalidated: {count: 1, details: ['requested by client']}
 }

有没有办法用hstore做到这一点?

你想要的看起来像“几乎是json”。你想要一个json,或者一些js对象还是什么?。。你能给它命名吗?。是的,我希望它看起来像一个json。也许你应该看看PostgreSQL中的json类型。你可以将hstore添加到json中,比如:hstore to json(hstore(array_agg('some_key'::text),array_agg('some_value'::text)),作为加载的用户数据井,
hstore
是平面的,单级的。不能以本机方式在其中嵌套多级数据。您可以将嵌套值展平为
文本
,并以这种方式嵌入它们,但这太可怕了。你真的很明显想要这里的
json