2013-08-27 39 views
2

我試圖得到以下兩個字符串的套疊的鍵的,在postgresdb保存爲hstore:獲取嵌套鍵hstore Postgres的

{"values"=>"{\"60\"=>[\"hallo\"], \"63\"=>[\"9\"], \"62\"=>[\"Nein\", \"Vielleicht\"], \"61\"=>[\"Ja\"]}", "comment"=>"[\"hmm\"]"}"}, 
{"values"=>"{\"60\"=>[\"test?\"], \"63\"=>[\"9\"], \"62\"=>[\"Ja\", \"Nein\"], \"61\"=>[\"Ja\"]}", "comment"=>"[\"kommentar23\"]"}"} 

要清楚,我怎麼能得到所有的鍵/數字在SQL?

我試過akeys函數並獲得「值」,這很好,這是第一個鍵,但我不知道如何獲得嵌套鍵? 我試圖用子查詢沒有成功。

有什麼建議嗎?

謝謝,帕特里克

回答

1

我說你hstore看起來更像扭曲JSON。您可以嘗試用:替換=>並解析它,例如,用python json module或者如果您使用9.3,則用native json methods解析它。

或者您可以得到skeys,再次將其轉換爲hstore並獲取值。