난 진자 평범한 코딩보다 sql이 제일 순수한 머리 쓰는 것 같음


대갈빡 굴리는 중이긴 한데 아직 잘 모르겠다.


일단 table은


create table user_setlist
(
bocco_user_id integer not null,
user_setlist_number integer not null,
user_setlist_name varchar(50) not null,
start_date date,
end_date date,
is_mon boolean not null,
is_tue boolean not null,
is_wed boolean not null,
is_thu boolean not null,
is_fri boolean not null,
is_sat boolean not null,
is_sun boolean not null,
is_week1 boolean not null,
is_week2 boolean not null,
is_week3 boolean not null,
is_week4 boolean not null,
is_week5 boolean not null,
displ_no integer not null,
tenant varchar(256),
creation_ts timestamp not null,
update_ts timestamp not null,
version integer not null,
constraint user_setlist_pk
primary key (bocco_user_id, user_setlist_number)
);


여기서 화면상에서 건너오는 json이 있는데


대략 bocco_user_id : 1

user_setlist_number : 2

뭐 이런 식임.


이걸로 저 테이블에 데이터를 넣을 건데


데이터에 넣기 전에 sql문으로


start_date, end_date 과 기간이 겹치는 것을 추출 (예를 들어 json의 start_date가 2022-07-01, end_date가 2022-08-01일 때 테이블 내부에 start_date: 2022-07-20, end_date: 2022-09-08이면 겹치는 걸로 처리)


플러스


주가 겹치고(is_week1, is_week2이런 것이 true이고) 동시에 요일이 겹치면 (is_mon등이 true) 중복 처리를 해서 입력이 안 되도록 하고 싶음.


그를 위해서 sql문을 작성하고 count같은 걸로 예를 들어 1이상이면 exception날리는 식으로 하고 싶은 것 같은데



대충 데이터 먼저 떠와서 백엔드에서 filter로 대충 주물럭거리고 처리하면 존나 쉬울 것 같은 걸 sql한 방으로 다 할 수 있지 않냐고 팀장이 씨발 우기는 중임


이거 sql문 어케 만들어야함