SQL/postgresql

[postgresql] eclipse, mybatis 사용 round does not exist

도미노& 2021. 11. 11. 16:13
org.postgresql.util.PSQLException: ERROR: function round(double precision, integer) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.

라는 에러를 만났는데 Console에 찍힌 쿼리를 실행해 보니 잘만 실행이 됐다.

 

 

UPDATE table SET
	amt = round(#{javaDouble1} * #{javaDouble2}, 2)
WHERE key = #{key}

쿼리는 이렇게 생긴 친구였는데, 검색을 좀 해 보니 round 앞에 넣은 변수가 java로 double 타입이라 그랬던 것 같다. (postgresql에서는 float8)

Console Log에도 있듯 round(double, integer)은 존재하지 않음.

 

 

 

round는 numeric으로 사용할 수 있으므로 아래와 같이 ::numberic을 붙여 casting 해 준다.

UPDATE table SET
	amt = round(#{javaDouble1}::numeric * #{javaDouble2}::numeric, 2)
WHERE key = #{key}