0

Given this table:

CREATE TABLE rollouts
(
 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
 device_id TEXT NOT NULL,
 is_active BOOLEAN NOT NULL DEFAULT FALSE
);

How can I ensure that for a given device_id, there is only ever one active rollout? Multiple inactive ones are fine, so a simple unique index doesn't cut it.

asked Jun 4, 2020 at 15:22

1 Answer 1

2

You can use a partial unique index:

create unique index on rollouts (device_id) 
where is_active;
answered Jun 4, 2020 at 15:46
1
  • Thanks, will try that out. Commented Jun 4, 2020 at 19:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.