반응형
MybatisError
org.postgresql.util.PSQLException: The column index is out of range: 2, number of columns: 1.
주로 오타 때문에 column갯수가 안맞게 인식되는경우에 발생한다고 한다.
이번 케이스는 주석을 <!-- -->를 사용해야 하는데 /* */를 사용해서 발생했다.
COALESCE(A,B)
A,B를 비교해서 Null이 아닌 값을 유지하면서 둘다 NotNull이라면 A의 값을 반환
A | B | COALESCE(A,B) |
1 | 2 | 1 |
Null | 3 | 3 |
4 | 1 | 4 |
Null | Null | Null |
<foreach collection="list" item="item" index="index" separator=";">
INSERT INTO public.data
(
data_seq
, var_version
)
VALUES
(
#{item.dataSeq}
<!--, COALESCE((SELECT max(var_version) + 1 이렇게 하면 list 입력시 마다 커짐-->
<!--, COALESCE((SELECT max(var_version) + 1 - #{index} 이렇게 하면 마지막 list에서 값이 작아짐-->
, COALESCE((SELECT max(var_version)
FROM cdp_data_variable
WHERE group_seq = #{item.groupSeq}), 1))
</foreach>
반응형
'Backend > DB 실무' 카테고리의 다른 글
01/09 회고 (0) | 2024.01.09 |
---|---|
[Mybatis] 대소문자 구분 없이 조회 (0) | 2023.11.10 |
[Mybatis] foreach문과 사용되는 Mybatis 요소 정의 (0) | 2023.10.31 |
[SQL] ROW_NUMBER()/RANK() OVER() (0) | 2023.10.18 |
[Mybatis] Mybatis XML 작성 템플릿 (0) | 2023.07.25 |