1

If I create the following table..

CREATE TABLE foo ( x int );

I can EXCLUDE the following,

WHERE x = <a duplicate value> (generic unique constraint)
WHERE x = <specific value>    (type of unique constraint reduce values that aren't specific to null)
WHERE x <> ANY OTHER value    (EXCLUDE WITH <>)

But, is there a clever way to permit

INSERT INTO foo (x) VALUES (0);
INSERT INTO foo (x) VALUES (1);

but, not

INSERT INTO foo (x) VALUES (1);
INSERT INTO foo (x) VALUES (0);

Or is there a module would otherwise let me do it as a function of the index and not with a trigger.

In summary, you can insert multiple values of 1 (or 0), but upon the first insertion of 1 the file is closed and no further insertion of 0 can be made, but 1 can continue to be inserted.

  • One little question... Why would you want to do this ? – KookieMonster Oct 2 '17 at 8:24
  • @KookieMonster I wanted to add it to this question, dba.stackexchange.com/a/187366/2639 Where I need the functionality – Evan Carroll Oct 3 '17 at 23:33
  • Do you want to exclude only the pair (1,0) (i.e. not allow insert of 1 when the 0 is already inserted) or any pair (b,a) where b>a? – ypercubeᵀᴹ Jun 19 '18 at 0:37
  • @ypercubeᵀᴹ updated the question. – Evan Carroll Jun 19 '18 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.