【发布时间】:2018-11-11 20:52:25
【问题描述】:
我有表 documents,我想选择列 foo 和 bar。还有comments 列jsonb。
但在comments 中,我只需要满足条件"isUser":false 的最后一个元素。
"select foo, bar, comments from documents
where comments @> '[{"isUser":false}]'
limit 1 " /*just limit by 1, the latest comment where isUser = false*/
这就是comments 列中 json 的样子:
[{
"text": "1 sample lorem ipsum",
"authorId": "0dcd5a36-2778-4fc4-bbc1-112ed61f1362",
"timestamp": "2018-11-11T08:46:39.608Z",
"isUser": false
},{
"text": "2 sample lorem",
"authorId": "0dcd5a36-2778-4fc4-bbc1-112ed61f1362",
"timestamp": "2018-11-11T08:46:41.237Z",
"isUser": true
},{
...]
对于comments,我只需要"isUser":false所在的最后一个对象
【问题讨论】:
-
向我们展示 json 的实际外观以及您希望从中看到的输出的一些示例。