I have a table like this
| id | reciever
| (bigint) |(jsonb)
------------------------------------------------------
| 1 | {"name":"ABC","email":"abc@gmail.com"}
| 2 | {"name":"DEF","email":"deef@gmail.com"}
How can I fetch name where id = 1
the output will be like this
| id | name
------------------------------------------------------
| 1 | ABC
Use the ->>
operator :
select id, receiver ->> 'name' as name
from the_table
where id = 1;
select id, receiver->'name'
from mytable
where id = 1
Check out other JSON operators and functions on the postgres documentation https://www.postgresql.org/docs/12/functions-json.html
You can run the following:
SELECT id, receiver->>'name' AS name
FROM mytable
WHERE id = 1;
The ->>
operator gets the text value from JSON data by the given key name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.