I use Postgres and jsonB column

I have the following table:

id(VAARCHAR(64)) | value(JSONB)
1                |[{"x": "10", "y": 1}, {"x": "32110", "y": 12}] 

X has always unique

I can add a new element in this sequence.

I can check that sequence contains the element with x value "10" or not.

But I can't **Remove element with the special value of x (remove value which contains x:"10")?

Find the maximum value of y?**

Can anybody help me with this?

1 Answer 1


Is a remove

 UPDATE table_name
    set jsonB_column_name=(SELECT jsonb_agg(z.a)
                                   FROM  (SELECT jsonb_array_elements(t.jsonB_column_name) as a
                                          FROM   table_namet
                                          where id='3a-a7ed-bf88dcdde0ab') z
                                   WHERE NOT a @> '{"x":"10"}')
    where id='1';

Is a search

select max(c.jsonb->>'y')
from (SELECT jsonb_array_elements(t.jsonB_column_name) as jsonb
      FROM   table_namet) as c;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.