JSONB text extraction operator ->>

Last updated: 2026-11-04

JSONB text extraction operator ->>

->> differs from -> in exactly one way, and it matters: ->> returns text instead of jsonb. Once a scalar is extracted you can compare it directly against string literals and cast it, for example (doc ->> 'age')::int. A missing key still yields NULL.

Kindoperator
Example LanguageSQL

📝 Syntax

jsonb ->> text        -- extract by key, returned as text
jsonb ->> integer     -- extract by array index, returned as text

Precedence: ->> is in the "any other operator" tier, below arithmetic and above comparison. Because it returns text, the left side of a comparison is usually a string: `doc ->> 'name' = 'Ada'`. The -> operator returns jsonb, so compare it against a jsonb literal: `doc -> 'name' = '"Ada"'::jsonb`.

⚙️ Parameters

jsonbThe source jsonb value; if NULL the result is NULL.
keyA text key; NULL when the key does not exist.
indexAn integer array index starting at 0; NULL when out of range or not an array.

Returns:The sub-value as text (plain text for scalars, JSON text for objects and arrays); NULL when the key or index does not exist.

▶ 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, pg_typeof(doc ->> 'name') AS value_type, doc ->> 'name' AS value_text FROM t_jsonb_text
id | value_type | value_text
---+------------+-----------
 1 | text       | Ada       
(1 row)

SELECT id, doc ->> 'address' AS address_text, doc ->> 'age' AS age_text, (doc ->> 'age')::int AS age_int FROM t_jsonb_text
id | address_text        | age_text | age_int
---+---------------------+----------+--------
 1 | {"city": "Beijing"} | 36       |      36
(1 row)

SELECT id, doc ->> 'missing' AS missing_text FROM t_jsonb_text
id | missing_text
---+-------------
 1 | NULL        
(1 row)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QWhen should I use ->> instead of ->?
AUse ->> when you want the value as ordinary text or a number: it compares directly and casts with ::int. Use -> when you need to drill further (chained access) or run jsonb operations.
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%

🙏 帮我们做得更好

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

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