0

I have a varchar field in PostgreSQL, let's say the column is 'address' and list is ['foo', 'bar', 'baz']. I want to find any row in my table that has any of those words.

How do I write it using BoolenBuilder to create predicate? or by any means

final var builder = new BooleanBuilder();
builder.and(qAccount.accAddress.eqAny(accountAddress.getAddressLine()));


Predicate predicate = builder.getValue();

** here ArrayPath<String[], String> accAddress1 = qAccount.accAddress;

Sumith
  • 1
  • 1

1 Answers1

0

The like operation is handled by using the like() or contains() functions (the diff is described there), so since you want to find any row that contains any of the words from your list, you would have to iterate and add each condition to your BooleanBuilder, something like this:

final var builder = new BooleanBuilder();

for (String address : accountAddress.getAddressLine()) {
    builder.or(qAccount.accAddress.like("%" + address + "%"));
}

Predicate predicate = builder.getValue();
Yahor Barkouski
  • 1,361
  • 1
  • 5
  • 21