Working on trying to convert the following Postgres Query into Jooq. I would love to implement this with JOOQ's features instead of just copying the SQL in.
Ultimately im trying to make this query in jooq.
SELECT * from content_block cb
JOIN content_block_data cbd on cbd.block_id = cb.id
WHERE cbd."data" @? '$.** ? (@.blockId == 120)';
Another instance of a similar query
SELECT *
FROM content_block_data
WHERE jsonb_path_query_first(data, '$.**.blockId') @> '120';
Another instance of a similar query
SELECT *
FROM content_block_data
WHERE jsonb_path_exists(data, '$.** ? (@.blockId == 120)');
What I have in java
@NotNull
Result<Record> parentBlockRecords =
dslContext.select(asterisk()).from(CONTENT_BLOCK_DATA
.join(CONTENT_BLOCK).on(CONTENT_BLOCK.ID.eq(CONTENT_BLOCK_DATA.BLOCK_ID)))
//.where(jsonbValue(CONTENT_BLOCK_DATA.DATA,"$.**.blockId").toString()
// .contains(String.valueOf(blockId)))
.fetch();
The where on this im having a hard time getting to work. The query can grab data from the DB, but just having a fair bit of trouble with this comparison.
And idea of the data in CONTENT_BLOCK_DATA.DATA
{
"blocks": [
{
"blockId": 120,
"__source": "block"
},
{
"blockId": 122,
"__source": "block"
}
]
}
Thanks for the help.