Merging Concatenating JSON(B) columns in query

后端 未结 10 1527
不思量自难忘°
不思量自难忘° 2020-12-08 09:40

Using Postgres 9.4, I am looking for a way to merge two (or more) json or jsonb columns in a query. Consider the following table as an example:

10条回答
  •  粉色の甜心
    2020-12-08 09:59

    FYI, if someone's using jsonb in >= 9.5 and they only care about top-level elements being merged without duplicate keys, then it's as easy as using the || operator:

    select '{"a1": "b2"}'::jsonb || '{"f":{"g" : "h"}}'::jsonb;
          ?column?           
    -----------------------------
     {"a1": "b2", "f": {"g": "h"}}
    (1 row)
    

提交回复
热议问题