Official Documentation: PostgreSQL JSON Functions
Operator | Right Operand Type | Description | Example |
---|---|---|---|
-> | int | Get JSON array element | '[1,2,3]'::json->2 |
-> | text | Get JSON object field | '{"a":1,"b":2}'::json->'b' |
->> | int | Get JSON array element as text | '[1,2,3]'::json->>2 |
->> | text | Get JSON object field as text | '{"a":1,"b":2}'::json->>'b' |
#> | array of text | Get JSON object at specified path | '{"a":[1,2,3],"b":[4,5,6]}'::json#>'{a,2}' |
#>> | array of text | Get JSON object at specified path as text | '{"a":[1,2,3],"b":[4,5,6]}'::json#>>'{a,2}' |
Id | Content |
---|---|
1 |
{ "name": "my json data 1", "size": { "length": 100, "width": 200, "isBig": false }, "array": [{ "id": 1 }, { "id": 2 }, { "id": 3 }] } |
2 |
{ "name": "my json data 2", "size": { "length": 100, "width": 200, "isBig": true }, "array": [{ "id": 1 }, { "id": 2 }, { "id": 3 }] } |
name
PropertySELECT "content" ->> 'name' FROM "example";
size.length
PropertySELECT "content" -> 'size' ->> 'length' FROM "example";
size.isBig = true
SELECT * FROM "example" WHERE ("content" -> 'size' ->> 'isBig')::bool IS TRUE;
id = 2
from the array
SELECT * FROM "example", json_array_elements("content" -> 'array') a
WHERE (a ->> 'id')::int = 2;
ยฉ 2025 juniyunapapa@gmail.com.