How do I modify fields inside the new PostgreSQL JSON datatype?

前端 未结 21 2167
孤独总比滥情好
孤独总比滥情好 2020-11-22 15:37

With postgresql 9.3 I can SELECT specific fields of a JSON data type, but how do you modify them using UPDATE? I can\'t find any examples of this in the postgresql documenta

21条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 16:19

    For those who use mybatis, here is an example update statement:

    
        update quiz_execution set answer_data = jsonb_set(answer_data, concat('{', #{qid}, '}')::text[], #{value}::jsonb), updated_at = #{updatedAt}
        where id = #{id}
    
    


    Params:

    • qid, the key for field.
    • value, is a valid json string, for field value,
      e.g converted from object to json string via jackson,

提交回复
热议问题