我有以下数据结构:
{
"proccess1": {
"error": "error1 description",
"nextRetryAt": "2018-02-22T07:39:00.325Z",
"attemptsMade": 148,
"firstFailedAt": "2018-02-16T06:40:41.327Z"
},
"proccess2": {
"error": "error2 description",
"nextRetryAt": "2019-03-16T06:41:01.566Z",
"attemptsMade": 77,
"firstFailedAt": "2016-03-15T04:35:12.248Z"
}
}
我的问题是如何构建查询
select *
from data
where data->[0]->>'nextRetryAt' = 'my passed value'
我不知道按键的名称proccess1
and proccess2
。他们可能有任何价值观。
https://www.postgresql.org/docs/current/static/functions-json.html https://www.postgresql.org/docs/current/static/functions-json.html
jsonb_object_keys
会帮助你
https://www.db-fiddle.com/f/9fB1pfb3BWv4v2wBUwU1Bd/0 https://www.db-fiddle.com/f/9fB1pfb3BWv4v2wBUwU1Bd/0
with c(j) as (values('{
"proccess1": {
"error": "error1 description",
"nextRetryAt": "2018-02-22T07:39:00.325Z",
"attemptsMade": 148,
"firstFailedAt": "2018-02-16T06:40:41.327Z"
},
"proccess2": {
"error": "error2 description",
"nextRetryAt": "2019-03-16T06:41:01.566Z",
"attemptsMade": 77,
"firstFailedAt": "2016-03-15T04:35:12.248Z"
}
}'::jsonb))
select j->jsonb_object_keys(j)->>'nextRetryAt' from c;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)