PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Durchsuchen des jsonb-Arrays in PostgreSQL

Sie können exists verwenden :

SELECT * FROM 
    (SELECT 
        '[{"id":1,"msg":"testing"},{"id":2,"msg":"tested"},{"id":3,"msg":"nothing"}]'::jsonb as data) 
    as jsonbexample 
WHERE 
    EXISTS (SELECT 1 FROM jsonb_array_elements(data) as j(data) WHERE (data#>> '{msg}') LIKE '%est%');

Um die Tabelle wie im Kommentar unten erwähnt abzufragen:

SELECT * FROM atable 
WHERE EXISTS (SELECT 1 FROM jsonb_array_elements(columnx) as j(data) WHERE (data#>> '{msg}') LIKE '%est%');