I've got a table TABLE
that contains a jsonb column named tags
. The tags
element in each row may or may not contain a field called group
. My goal is to group by tags.group
for all rows where tags
contains a group
field. Like the following postgres query:
select tags->>'group' as group, sum(n) as sum
from TABLE
where tags ? 'group'
group by tags->>'group';
I'm trying to turn it into JOOQ and cannot find out how to express the where tags ? 'group'
condition.
For example,
val selectGroup = DSL.field("{0}->>'{1}'", String::class.java, TABLE.TAGS, "group")
dsl().select(selectGroup, DSL.sum(TABLE.N))
.from(TABLE)
.where(TABLE.TAGS.contains('group'))
.groupBy(selectGroup)
This is equivalent to testing contains condition @>
in postgres. But I need to do exists condition ?
. How can I express that in JOOQ?