Вызов префикса функций базы данных инфикса - PullRequest
0 голосов
/ 06 апреля 2020

Поэтому я хочу использовать функцию REGEXP EclipseLink в моем построителе критериев, чтобы сопоставить id_str столбец моей сущности с выражением регулярного выражения.

Использование, которое они документируют в приведенной выше ссылке это

WHERE column_name REGEXP '<here be regex>'

Но я не могу поместить это в CriteriaBuilder, поэтому вместо этого я ставлю

WHERE REGEXP (column, '<here be regex>')

, предполагая, что именно так и действует инфиксный оператор.

@Override
public Predicate visit(CriteriaBuilder cb, IdStringRegexSearchElement searchElement) {
    Expression<String> identificationString = root.get("identificationString");
    String regexPattern = searchElement.getRegex().getPattern();
    return matchesRegex(cb, identificationString, regexPattern);
}

private Predicate matchesRegex(CriteriaBuilder cb, Expression<String> target, String regexPattern){
    Expression<Boolean> idStrMatchesRegex = cb.function("REGEXP", Boolean.class, target, cb.literal(regexPattern));
    return cb.isTrue(idStrMatchesRegex);
}

Кажется, это не сработает:

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.6.v20200131-b7c997804f): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: function regexp(character varying, character varying) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.
  Position: 273
Error Code: 0
Call: SELECT DISTINCT ID, ... , id_str, ... FROM my_foo WHERE (REGEXP(id_str, ?) = ?)
    bind => [2 parameters bound]

Мне кажется, что вызов выглядит корректно, поскольку он воспроизводится так, как я ожидал.

Итак Я предполагаю, что просто не могу вызывать инфиксную функцию таким образом.

Как правильно ее вызвать?

...