postgres如何更新追加和剪切字符串

时间:2016-06-15 09:07:57

标签: postgresql hstore

我的表格如下:

id | name  | type |                                       info             | ksid |                iv                
----+-------+------+-------------------------------------------------------+------+----------------------------------
  1 | local |    1 | "keyId"=>"1234", "server"=>"http://10.10.13.10/keys/" |      | 30646462653237643965373830343334

如何将字符串附加到info以使信息值为

"keyId"=>"1234", "server"=>"http://10.10.13.10/keys/", "period"=>"0"

改变之后,如何改回

"keyId"=>"1234", "server"=>"http://10.10.13.10/keys/"

1 个答案:

答案 0 :(得分:2)

你可以通过以下方式增加价值:

UPDATE yourtable SET info = info || '"period"=>"0"' :: hstore WHERE id = 1;

并删除:

UPDATE yourtable SET info = delete(info, 'period') WHERE id = 1;