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

前端 未结 21 2174
孤独总比滥情好
孤独总比滥情好 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:15

    If you want to use values from other columns in your JSON update command you can use string concatenation:

    UPDATE table
    SET column1 = column1::jsonb - 'key' || ('{"key": ' || column2::text ||  '}')::jsonb
    where ...;
    

提交回复
热议问题