Joshua Rajandiran
Joshua Rajandiran

Reputation: 2928

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

Upvotes: 0

Views: 61

Answers (1)

Andreea Craciun
Andreea Craciun

Reputation: 310

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);

Upvotes: 1

Related Questions