How to bind values for ANY( VALUES (''),('')...) postgres syntax in R2DBC DatabaseClient of spring boot reactive framework

304 views Asked by At

I want to bind my list of string values to a specific query I am using. Here is a part of my query

WHERE (item_id = ANY(VALUES :item_id ))

Now, as per postgres, they follow syntax like this

WHERE (item_id = ANY(VALUES ('item1'),('item2'),('item3') ))

And what i am doing is

databaseClient.sql(myQuery)
                    .bind("item_id", Parameter.fromOrEmpty(itemsIds, String.class))
                    .map(...)
                    ... 

But this does not bind the values properly as per syntax of postgres because the syntax requires each values enclose within brackets. I even tried mapping all my List itemIds and added '(' & ')' at start and end respectively, but this also didn't worked. I can achieve what I want by StringBuilder and manually forming the queries, but I don't want to follow that approach, because I have to everytime form the query I require. Also, I dont want to use ANY(ARRAY[...]), my use case will be use only ANY(VALUES (),(),()...).

Any help on how to achieve this?

0

There are 0 answers