Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check JOOQ array type field is empty

Given there is Postgres array type, how to assemble where condition to check if it is empty.

I have tried to use the following clause, it did not work as expected.

 where = if (arrayExists== true) {
    where.and(DSL.length(USERS.ACCOUNT_IDS.name).greaterThan(0))
 } else {
    where.and(DSL.length(USERS.ACCOUNT_IDS.name).equal(0))
 }

NOTE: arrayExists is an external parameters from outside.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Out of the box, jOOQ supports the CARDINALITY() function via DSL.cardinality(Field<? extends Object[]>). It’s what you’d write in PostgreSQL and standard SQL as well:

select cardinality(array[1, 2])

Producing

|cardinality|
|-----------|
|2          |
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading