Created
April 5, 2013 21:50
-
-
Save andrefreitas/5322935 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Remove the old score from that costumer in that product | |
DROP TRIGGER IF EXISTS new_score_before ON stores; | |
DROP FUNCTION IF EXISTS new_score_before(); | |
CREATE OR REPLACE FUNCTION new_score_before() RETURNS trigger as $$ | |
BEGIN | |
DELETE FROM products_scores | |
WHERE NEW.user_id = products_scores.user_id AND | |
NEW.product_id = products_scores.product_id; | |
RETURN NEW; | |
END; | |
$$ LANGUAGE plpgsql; | |
CREATE TRIGGER new_score_before BEFORE INSERT ON products_scores | |
FOR EACH ROW EXECUTE PROCEDURE new_score_before(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment