JSONB containment operator @>

Last updated: 2026-11-04

JSONB containment operator @>

@> reports whether the left jsonb contains the right jsonb. Containment is recursive and structural: every key/value pair of an object must be matched on the left, and every element of the right array must be present in the left array. It is the workhorse for filtering jsonb and far more efficient than comparing keys one by one. The reverse relation is <@.

Kindoperator
Example LanguageSQL

📝 Syntax

jsonb @> jsonb        -- left contains right
jsonb <@ jsonb        -- left is contained by right

Precedence: @> is in the "any other operator" tier, below arithmetic, above comparison, and at the same level as -> and ->>. `doc @> '{"a":1}'` is therefore one boolean expression that can go straight into WHERE or be combined with AND/OR. Write the right-hand side as a jsonb constant so it is not confused with text.

⚙️ Parameters

leftThe left jsonb, which may contain the right side; if NULL the result is NULL.
rightThe right jsonb, the content being looked for; if NULL the result is NULL.

Returns:The boolean true, false, or NULL when either operand is NULL.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

SELECT id, doc @> '{"active": true}' AS has_active, doc @> '{"user": {"name": "Ada"}}' AS has_nested FROM t_contains ORDER BY id
id | has_active | has_nested
---+------------+-----------
 1 | true       | true      
 2 | false      | false     
(2 rows)

SELECT id, doc @> '{"user": {"tags": ["db"]}}' AS has_array_item FROM t_contains ORDER BY id
id | has_array_item
---+---------------
 1 | true          
 2 | false         
(2 rows)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QHow does @> differ from =?
A= checks whether two jsonb values are exactly equal (same keys, values and structure); @> only requires the left side to contain the right, a subset test. `{"a":1,"b":2}` @> `{"a":1}` is true, while = between them is false.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏