I would like to filter out keys (given in an array of strings - ["key2"]) in a given column on an SQL table, say:
{ key1: val1, key2: val2, key3: val3 }
|--row---|-object--|---value----|
|---1----|--obj1---|--sum(obj1)-|
|---2----|--obj2---|--sum(obj2)-|
|---3----|--obj3---|--sum(obj3)-|
I want to be able to do this with the use of SQL and filter all keys of an array for each row in parallel.
So for example, if I had these objects:
obj1 = "{ key1: val1, key2: val2, key3: val3 }"
obj2 = "{ key1: val1, key2: val2 }"
obj3 = "{ key1: val1, key2: val2, key3: val3, key4: val4, key5: val5 }"
and an array of ["key1", "key4"]
I would get new table with new objects and new values as:
obj1 = "{ key2: val2, key3: val3 }" , val = val2+val3
obj2 = "{ key2: val2 }" , val = val2
obj3 = "{ key2: val2, key3: val3, key5: val5 }" , val = val2+val3+val5
Is it possible?
I tried to use JSON_EXTRACTOR in order to extract the object as a JSON format and manipulate the rows with the filter function one by one but it is not very efficient when I think about it, and it is not using the query to do the filtering.