简体   繁体   English

如何在 jsonb 列中获取参数

[英]How can i fetch a parameter in jsonb column

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如何获取name where id = 1

the output will be like this output 将是这样的

| 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 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. ->>运算符通过给定的键名从 JSON 数据中获取文本值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM