'support for varchar[] array type in R2DBC Postgres Criteria

I am trying to build a query similar to the below query using criteria query having varchar[] column in Postgres.

SELECT * 
FROM table_name 
WHERE (arrays['value1','value2']::varchar[] && column_name) 

But it appears that there is no out of the box support for varchar[] in R2dbcEntityTemplate. Is there any way to achieve this?



Solution 1:[1]

From your question, I'm not sure if a specific stack requirement is present, or if third party libraries are an option. If they are, you could use jOOQ's R2DBC support to handle the data type binding for you, a bit more transparently. With jOOQ, you'd write:

Flux<TableNameRecord> flux =
Flux.from(
    ctx.selectFrom(TABLE_NAME)
       .where("{0} && {1}"), 
           DSL.val(new String[] { "value1", "value2" }),
           TABLE_NAME.COLUMN_NAME
));

The above approach is using plain SQL templating to use the && operator. The DSL.val() call creates an array bind variable, which produces a $1::varchar[] expression for you, behind the scenes, and correctly binds the array to the R2DBC driver.

Solution 2:[2]

Perhaps it would possibly be the case of using a converter? Please take a look to this link:

Spring RD2DBC mapping

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lukas Eder
Solution 2 Ivan Costa