JSONB: filter rows with @>
attrs->>'wireless' = 'true' would work for filtering on a single JSON field,
but it means comparing against the text 'true', not a real boolean - easy to
get subtly wrong once the JSON gets more nested. Postgres has a better tool
for "does this JSON document contain this shape": the @> containment
operator. attrs @> '{"wireless": true}' asks "does the attrs JSON contain
a wireless key set to true, alongside whatever else it has?" - and it
compares against the real JSON value, not text.
Same products table as the last lesson: id, name, attrs (JSONB,
with a "wireless" boolean in every row).
Your task: return the name of every product where attrs shows
wireless as true.
You'll practice:
- Filtering on a JSONB field's real type (boolean) with
@>, not a text comparison
- Writing a JSON literal inside a SQL string