gpt4 book ai didi

json - 从 Postgres 中的 jsonb 通过未知键获取元素

转载 作者:行者123 更新时间:2023-11-29 12:02:35 25 4
gpt4 key购买 nike

我有以下数据结构:

{
"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'

我不知道键 process1process2 的名称。他们可能有任何值(value)观。

最佳答案

https://www.postgresql.org/docs/current/static/functions-json.html

jsonb_object_keys 会帮助你

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;

关于json - 从 Postgres 中的 jsonb 通过未知键获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48923271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com