Cannot grant user badge because badge id, user id, and post id is same


(Mohit Gupta) #1

I have written a badge granting query for every time you receive a like but it seems that I cannot grant those badges because some of those badges have same badge id, user id and post id. Is their any solution for this problem?
Can i add any other parameter like time-stamp to distinguish them.


(Jeff Atwood) #2

I think there is something terribly wrong with your badge query.


(Rafael dos Santos Silva) #3

There’s and unique index that doesn’t allow more than one badge by post_id:

CREATE UNIQUE INDEX index_user_badges_on_badge_id_and_user_id_and_post_id
  ON user_badges
  USING btree
  (badge_id, user_id, post_id)
  WHERE post_id IS NOT NULL;

(Mohit Gupta) #4

@Falco Can i add more parameter like a timestamp that can distinguish those badges or is their a way so that property of this unique index can be made non-unique.