简体   繁体   English

使用 json 的 postgres 查询

[英]postgres query with json

I have JSON in a column named payload :我在名为payload的列中有 JSON :

"status":"E",
"statusText":"{\"status\":\"INVALID\",\"description\":\"Данные некорректны\}",
"errorCode":"smev_error"

I know how to get only statusText :我知道如何只获取statusText

SELECT payload::json->>'statusText' FROM table_name;

It will show me它会告诉我

-[ RECORD 1 ]----------------------------------------------------
?column? | {"status":"INVALID","description":"Данные некорректны"}

I need to get only description .我只需要得到description I found out construction with #> can resolve my trouble but I don't really know how to build a query with that.我发现使用#>构建可以解决我的问题,但我真的不知道如何使用它构建查询。 So I want to get something like that:所以我想得到这样的东西:

?column? | {"Данные некорректны"}

Could you help me please?请问你能帮帮我吗?

Just cast once again to have the status text as json as well.只需再次将状态文本转换为json

SELECT (payload::json->>'statusText')::json->>'description' AS description
       FROM table_name;

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

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