Updating json field in Postgres

前端 未结 3 1914
眼角桃花
眼角桃花 2021-02-20 05:53

Querying Postgres 9.3 by json field is really great. However i couldn\'t find a formal way to update the json object, for which i use an internal function written in plp

3条回答
  •  耶瑟儿~
    2021-02-20 06:32

    Solved

    The problem with the above plpythonu function is that it relates to "value" as a string no matter if it's actually a complex json object. The key to solve it is to add eval() around value:

    js[key] = eval(value)
    

    That way the json string (named 'value' in this example) looses it's outer enclosing double quotes "{...}" and become an object.

提交回复
热议问题