I created a table for to store day off data of users. After, set a unique index for multi column but when exec insert sql, it duplicates datas again
Here's my DDL:
create table day_off_movements
(
id bigserial
primary key,
user_id bigint
constraint fk_day_off_movements_user
references users,
proxy_user_id bigint
constraint fk_day_off_movements_proxy_users
references users,
reason text,
day_off_start_date timestamp with time zone,
day_off_end_date timestamp with time zone,
used_days bigint,
created_at timestamp with time zone,
updated_at timestamp with time zone
);
Index:
create unique index idx_day_off_all
on day_off_movements (user_id, proxy_user_id, day_off_start_date, day_off_end_date);
Control query:
SELECT user_id,proxy_user_id,day_off_end_date,day_off_start_date,count(*)
FROM public.day_off_movements t
GROUP BY user_id, proxy_user_id, day_off_end_date, day_off_start_date
Output as json:
[
{
"user_id": 961,
"proxy_user_id": null,
"day_off_end_date": "2020-07-29 00:00:00.000000 +00:00",
"day_off_start_date": "2020-07-27 00:00:00.000000 +00:00",
"count": 3
}
]
What is my wrong? Thanks for your helps.