The question may seems stupid but I am stuck on executing that kind of query:
UPDATE user SET productArr = ARRAY[ARRAY[2,2],ARRAY[3,2],ARRAY[1,3]] WHERE id = 1;
within a @Query
Spring Data.
I defined my repository method like:
@Modifying
@Query(value = """
UPDATE user
SET productArr = :productArr WHERE id = :userId
""", nativeQuery = true)
void updateProductArr (@Param("productArr") String productArr, @Param("userId") Long userId);
I set String productArr="ARRAY[ARRAY[2,2],ARRAY[3,2],ARRAY[1,3]]"
The error is:
org.postgresql.util.PSQLException: ERROR: column "productArr" is of type text[] but expression is of type text
I tried to change the type of productArr
from String to String[]
or List<String>
without success.
I also tried this solution: UPDATE user SET productArr = REPLACE(:productArr,'"','') WHERE id = :userId
but same result.
Please note that when I run that query on a database console it works well. Thank you in advance for your help.
> or String[][]. For detail information how to map a 2d arrays in Java Hibernate visit this url. https://stackoverflow.com/questions/4099237/how-to-map-a-2-d-matrix-in-java-to-hibernate-jpa - Maybe help you.
– Ramin Faracov Jul 11 '23 at 15:36