PostgreSQL
 SQL >> Database >  >> RDS >> PostgreSQL

Come filtrare un array JSON per ogni riga restituita?

Puoi usare json_array_elements per disperdere (unnest) il JSON e array_agg per ricomporlo dopo il filtraggio. Qualcosa del genere:

SELECT t.id, array_to_json(array_agg(j)) FROM your_table t, json_array_elements(t.jsonColumn) j WHERE j->>'field' = 'abc' GROUP BY id;