I have the following tables:
create workers (
id SERIAL PRIMARY KEY,
name STRING
);
create works_zones (
id SERIAL PRIMARY KEY,
area_name String,
work_from TIME WITHOUT TIMEZONE,
work_until TIME WITHOUT TIMEZONE
)
create table shifts (
id SERIAL PRIMARY KEY,
worker_id INT,
day_of_week INT,
work_zone INT,
CONSTRAINT fk_worker FOREIGN KEY(worker_id) REFERENCES workers(id) ON DELETE CASCADE,
CONSTRAINT fk_work_zone FOREIGN KEY(work_zone) REFERENCES works_zones(id) ON DELETE CASCADE
)
And in my table shifts I have the folowing records:
id | worker_id | day_of_week | work_zone |
---|---|---|---|
1 | 1 | 1 | 1 |
2 | 1 | 1 | 1 |
3 | 2 | 2 | 1 |
3 | 2 | 2 | 1 |
In my case I want to apply a unique Index on columns worker_id
, day_of_week
, work_zone
at table shifts
:
CREATE UNIQUE INDEX CONCURRENTLY unique_day_zone_worker ON shifts (worker_id,work_zone,"day_of_week");
But according to my records will fail. Therefore, I would like to detect duplicate records so I can manually fix them up. Any Ideas how I can do it?
In other wqords I want to detect the shift.id
that have duplicate records at columns worker_id
,day_of_week
,work_zone
.