Medium sql

PostgreSQL JSONB containment query

Problem

Query JSONB column where object contains {"active": true}.

Hints
  • @> operator, ->> for text

Your practice code

Ready — edit the code above and click Run.

Solution

SELECT id, data->>'city' AS city
FROM profiles
WHERE data @> '{"active": true}'::jsonb;

Try solving on your own first, then reveal the official answer.

Explanation

@> checks JSON containment; ->> extracts text field.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details