Skip to main content
added 9 characters in body
Source Link
McNets
  • 23.9k
  • 11
  • 50
  • 89

Postgres 9.2 allows you to use string_to_array and unnest, you can use it to get the desired result.

create table foo(id int, allowed_types varchar(256));
insert into foo values (1, '3,4,5,13,14');

1 rows affected

with a as
(
    select id, unnest(string_to_array(allowed_types, ',')) elem
    from foo
)
select id, array_aggstring_agg(elem, ',')
from a 
where elem not in ('4','5')
group by id
id | array_aggstring_agg
-: | :---------
 1 | {3,13,14}   

dbfiddle herehere

Postgres 9.2 allows you to use string_to_array and unnest, you can use it to get the desired result.

create table foo(id int, allowed_types varchar(256));
insert into foo values (1, '3,4,5,13,14');

1 rows affected

with a as
(
    select id, unnest(string_to_array(allowed_types, ',')) elem
    from foo
)
select id, array_agg(elem)
from a 
where elem not in ('4','5')
group by id
id | array_agg
-: | :--------
 1 | {3,13,14}

dbfiddle here

Postgres 9.2 allows you to use string_to_array and unnest, you can use it to get the desired result.

create table foo(id int, allowed_types varchar(256));
insert into foo values (1, '3,4,5,13,14');

1 rows affected

with a as
(
    select id, unnest(string_to_array(allowed_types, ',')) elem
    from foo
)
select id, string_agg(elem, ',')
from a 
where elem not in ('4','5')
group by id
id | string_agg
-: | :---------
 1 | 3,13,14   

dbfiddle here

Source Link
McNets
  • 23.9k
  • 11
  • 50
  • 89

Postgres 9.2 allows you to use string_to_array and unnest, you can use it to get the desired result.

create table foo(id int, allowed_types varchar(256));
insert into foo values (1, '3,4,5,13,14');

1 rows affected

with a as
(
    select id, unnest(string_to_array(allowed_types, ',')) elem
    from foo
)
select id, array_agg(elem)
from a 
where elem not in ('4','5')
group by id
id | array_agg
-: | :--------
 1 | {3,13,14}

dbfiddle here