Skip to content

Instantly share code, notes, and snippets.

@andrefreitas
Created April 5, 2013 21:50
Show Gist options
  • Save andrefreitas/5322935 to your computer and use it in GitHub Desktop.
Save andrefreitas/5322935 to your computer and use it in GitHub Desktop.
-- 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