I am trying to achieve below using Spring JPA.
update test as t set
column_a = c.column_a
from (values
('123', 1),
('345', 2) // this will be dynamic
) as c(column_b, column_a)
where c.column_b = t.column_b;
Is there a way to pass the values from spring jpa using native query?
I would suggest that you first serialize your dynamic data as text representing a JSON array of any length - or even an empty one - like this
and use this native query passing the above text as a single parameter:
Notes:
::is escaped as\\:\\:;(j->>0)\\:\\:integerinstead ofj[0]\\:\\:integerandj->>1instead ofj[1]\\:\\:textAlternative
Serialization format:
Query:
This approach - serialize complex dynamic data as JSON text then pass it as a single
Stringparameter to a native query and let the query do the rest - is quite generic and works well in many different cases.