1

Table structure is:

CREATE TABLE mine_check.meta
(
  sl_no bigserial NOT NULL,
  tags jsonb NOT NULL DEFAULT '[]'::jsonb
);

Table looks like

    sl.no    tags
    1        [120,450]
    2        [120]
    3        [450,980,120]
    4        [650]

I need to delete 120 from the tags column - having no key

I tried reading many places - there they had key to update or delete.

How should I progress ?

1 Answer 1

1

I am afraid that it has to be done the hard way - unnest the JSONB array, select and filter from it and aggregate back into a JSONB array.

select sl_no, 
(
  select jsonb_agg(e::integer) 
  from jsonb_array_elements_text(tags) e 
  where e <> 120::text
) tags
from mine_check.meta;
Sign up to request clarification or add additional context in comments.

2 Comments

I'm using 9.4 postgress version - jsonb_agg is not supported in that - is there any other way?
Yes, under PG 9.4 you may replace jsonb_agg(e::integer) with json_agg(e::integer)::jsonb. TIme to update though.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.