In PostgreSQL I have a table (Table) that contains an id column (ID) and another column (Values) that contains an array of strings. I have a select query (SelectQuery) that gets me an ID that matches Table.ID, as well as an array of values (RemoveValues). I would like to now remove from the Values array, any strings that are contained in the RemoveValues array that match on ID, updating Table.
--Table--
ID Values
-- ----------------------------
1 {string1, string2, string3}
2 {string1, string2, string3}
...
--SelectQuery--
ID RemoveValues
-- ----------------------------
1 {string2}
2 {string1, string2}
...
Execute query that I can't figure out
--Table--
ID Values
-- ----------------------------
1 {string1, string3}
2 {string3}
...
I can't seem to figure out a good way to do this, I've played with a number of joins and the sql array methods and haven't found anything that works. Is there's a way to loop the remove() method for each element in RemoveValues? I've also tried something like this with no luck:
select array_agg(elem)
from Table, unnest(Table.Values) elem
where elem <> all(
SelectQuery )
);
I'm feeling like my remaining option is a bash script, unless anyone can suggest a path forward using SQL?