티스토리 뷰

SW개발/Database

update null 처리

개소왕 2020. 4. 10. 10:26

* 개요 

Numeric 로 선언한 max_length 란 컬럼이 있다

(자바 Integer 선언)

 

update 시 null 을 대입하면 다음 오류 발생

 

Caused by: org.postgresql.util.PSQLException: ERROR: column "max_length" is of type numeric but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.

 

로그에 찍히는

UPDATE ... SET max_length = NULL 은 정상동작하는 쿼리인데도 오류

 

 

* 원인

mybatis 의 파라메터 대입하는 메서드 내부에서 Integer 가 아닌 int 를 사용하면서 null 을 사용 못하는것.

 

 

* 해결

#{maxLength, jdbcType=INTEGER}

 

- 이걸 모를때는 Integer 대신 STRING 을 반환하면 getMaxLengthNullable() 이란 메서드를 따로 선언해서 

#{maxLengthNullable} 로 쓰기도 했었음.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함