0

I have the following json:

{"john": 34, "alex": 56, "daniel": 90}

However I would like to add another value

{"harry": 78}

or alter an existing value

{"john": 39}

How would I go about doing this?

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
user15178581
  • 57
  • 1
  • 4
  • maybe this post will help u [Post](https://stackoverflow.com/questions/18209625/how-do-i-modify-fields-inside-the-new-postgresql-json-datatype) – MohaMed Mar 28 '21 at 14:41

1 Answers1

0

You can directly use concatenation operators without need of JSONB_INSERT or JSON_SET functions (as having no extra nested elements along with extra keys) such as

UPDATE tab
   SET jsdata = jsdata || '{"harry":78}'::JSONB || '{"john":39}'::JSONB 

Demo

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55