0

I am trying to configure unique constraint on the combination on values of 2 columns.

ExpID1 points to some String
ExpID2 points to some other String
MatchValue is the Match Score for the two Strings.

Create tbl_A (
   ExpID1 INTEGER NOT NULL,
   ExpID2 INTEGER NOT NULL,
   MatchScore NUMERIC NOT NULL,
   PRIMARY KEY (ExpID1 , ExpID2));

Because the match score between the values against ExpID1 and ExpID2 is going to be the same
I don't want to store the entry twice.

INSERT INTO tbl_A VALUES(1,2, 0.988)
INSERT INTO tbl_A VALUES(2,1, 0.988) -- This should fail because the combination is not unique.

Any solution will be greatly appreciated.

Jim Jones
  • 18,404
  • 3
  • 35
  • 44
SHI2RG
  • 1
  • 1
  • 1
    This might help you: https://stackoverflow.com/questions/23533184/primary-key-for-multiple-column-in-postgresql – ROOT Jan 13 '20 at 16:58
  • As an alternative to the suggested you can create a check constraint that enforces relationship between id1 and id2. alter table tbl_a add constraint id1LTid2_ck check (expid1 – Belayer Jan 13 '20 at 18:47

0 Answers0