Thanks for your reply Lucas.
I actually ended up creating this as a CustomField<> because i use it in several selects and conditional checks.
public class TsQueryField<R extends Record> extends CustomField<Boolean> {
private Collection<String> queries;
private TableField<R, Object> queryField;
public TsQueryField(TableField<R, Object> field, Collection<String> queries) {
super(field.getName(), new DefaultDataType(SQLDialect.POSTGRES, Boolean.FALSE.getClass(), "Boolean"));
this.queryField = field;
this.queries = queries;
}
public void toSQL(RenderContext context) {
CastMode castMode = context.castMode();
context.castMode(CastMode.NEVER).formatSeparator()
.visit(queryField)
.sql(" @@ ")
.visit(inline(MiscUtils.join(queries, "|")))
.sql("::tsquery")
.castMode(castMode);
}
}
However I am running into a problem when i try to check if this column is true. for example i am using:
.and(fnameTsQuery.isTrue().or(lnameTsQuery.isTrue()))
where both fnameTsQuery and lnameTsQuery variables are of type TsQueryField as defined above. This is generating SQL equivalent to the following:
"public"."test"."s_fnames" @@ 'hoover|greg'::tsquery = ?
I am unable to get rid of that ?. Is this a bug or am i doing something wrong here?