Search code examples
postgresqljsonb

Editing a jsonb value in postgresql?


I have a jsonb column that stores values like this:

{"v":"0","c":"ACC",...}

I'd like to update some of the v values to 1

Is there any built-in function to do that in postgresql?

E: I'm using v9.6


Solution

  • With Postgresql 9.5

    UPDATE test SET data = data - 'v' || '{"v":1}' WHERE data->>'c' = 'ACC';
    

    OR

    UPDATE test SET data = jsonb_set(data, '{v}', '1'::jsonb);