I have a table like this:
CREATE TABLE schema.mytable
(
id serial NOT NULL,
number integer NOT NULL,
state boolean NOT NULL,
);
I need to create an unique set of ´number´ but, the state column has to be true; if the state column is false, the numbers can be repeated, here is a example of what I need to be valid:
id number state
1 123 true
2 124 true
3 125 true
4 123 false
5 129 false
as you can see, number 123 is repeated but in one case the state is false and the other is true; this is incorrect:
id number state
1 123 true
2 124 true
3 125 true
4 123 true (*incorrect)
5 129 false
Also, it is possible that 123 is repeated two or more times with the false state; How can I achieve this?