Concept Flow - JSONB containment (@>) operator
Start with two JSONB values
Check if left JSONB contains right JSONB
Return TRUE
End
The operator checks if the left JSONB value contains the right JSONB value and returns true or false accordingly.
SELECT '{"a":1, "b":2}'::jsonb @> '{"a":1}'::jsonb AS contains;
| Step | Left JSONB | Right JSONB | Containment Check | Result |
|---|---|---|---|---|
| 1 | {"a":1, "b":2} | {"a":1} | Does left contain right? | TRUE |
| 2 | {"a":1, "b":2} | {"b":3} | Does left contain right? | FALSE |
| 3 | {"a":1, "b":{"c":3}} | {"b":{"c":3}} | Does left contain right? | TRUE |
| 4 | {"a":1, "b":{"c":3}} | {"b":{"c":4}} | Does left contain right? | FALSE |
| Variable | Start | Check 1 | Check 2 | Check 3 | Check 4 |
|---|---|---|---|---|---|
| Left JSONB | {"a":1, "b":2} | {"a":1, "b":2} | {"a":1, "b":2} | {"a":1, "b":{"c":3}} | {"a":1, "b":{"c":3}} |
| Right JSONB | {"a":1} | {"b":3} | {"b":{"c":3}} | {"b":{"c":4}} | {"b":{"c":4}} |
| Result | TRUE | FALSE | TRUE | FALSE |
JSONB containment (@>) operator: - Syntax: left_jsonb @> right_jsonb - Returns TRUE if left contains right JSONB exactly - Works recursively on nested JSON objects - Useful for checking presence of key-value pairs - Returns FALSE if any key or value mismatches