I have table documents
, I want to select columns foo and bar. And also the column comments
which is jsonb
.
But in comments
I only need the last element that meets condition "isUser":false
.
"select foo, bar, comments from documents
where comments @> '[{"isUser":false}]'
limit 1 " /*just limit by 1, the latest comment where isUser = false*/
This is how the json looks liks inside comments
column:
[{
"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
},{
...]
For comments
I only need the last object in which "isUser":false