I have the query to search for ids in jsonb column, the array can contain many id's.
Say I have data like this
id | act | act_id | from_ids | object_ids | post_date
2 post 1 {"2":"1494308197","3":"1494308198","4":"1494308199"} {"items":["104564"]} 1494308197
And a query like this
SELECT an.*
FROM activity_network an
WHERE an.from_ids ?| ARRAY['2','3'];
That query will return the row because it finds 2 and 3. But how can I return what it finds in it's own column. So that it returns 2,3 in text or json format or something like that in the results as well.
I tried this
SELECT an.*, jsonb_each_text(from_ids) b
FROM activity_network an
WHERE an.from_ids ?| ARRAY['2','3'];
But that creates 3 rows with a b column each one with the value 2, 3 and 4. I want 1 row with b column containing both 2 and 3 which is what I searched on.
Is that possible?
example result that I'm looking for. notice the last column. I put it as column delimited for demo purpose. it can be any format I can use.
2 | post | 1 | {"2":"1494308197","3":"1494308198","4":"1494308199} | {"items":["104564"]} | 1494308197 | 2,3}