Last active
January 23, 2025 22:39
-
-
Save dotJoel/f7d8445b538bf1a2bec3556f3f4f8d97 to your computer and use it in GitHub Desktop.
Using JPA, here is how I created a predicate that searches a JSONB column for any of the provided keys.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
builder.equal( | |
builder.function( | |
"JSONB_EXISTS_ANY", | |
Boolean.class, | |
root.get("nameOfJsonbColumnToSearch"), | |
builder.function( | |
"string_to_array", | |
String.class, | |
builder.literal(String.join(",", setOfValuesToSearchFor)), | |
builder.literal(",") | |
) | |
), | |
true | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/shrug
doesn't seem proper in retrospect. i mean, it works, but the point of JSONB is to be able to efficiently get keys. i couldn't find a way to do it at the time, hence this hack.