Reputation: 125
I have a table like this
| id | reciever
| (bigint) |(jsonb)
------------------------------------------------------
| 1 | {"name":"ABC","email":"[email protected]"}
| 2 | {"name":"DEF","email":"[email protected]"}
How can I fetch name where id = 1
the output will be like this
| id | name
------------------------------------------------------
| 1 | ABC
Upvotes: 0
Views: 38
Reputation: 2029
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.
Upvotes: 0
Reputation: 28233
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
Upvotes: 0
Reputation:
Use the ->>
operator:
select id, receiver ->> 'name' as name
from the_table
where id = 1;
Upvotes: 1