我为创建了一个表来存储用户的休假数据.之后,为多列设置唯一索引,但当EXEC插入SQL时,它会再次复制数据
这是我的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
);
索引:
create unique index idx_day_off_all
on day_off_movements (user_id, proxy_user_id, day_off_start_date, day_off_end_date);
控制查询:
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
输出为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
}
]
我哪里不对劲? 谢谢你的帮助.