coryd.dev/queries/triggers/decrement_total_plays.psql

20 lines
388 B
Text

BEGIN
UPDATE artists
SET total_plays = total_plays - 1
WHERE name_string = OLD.artist_name;
UPDATE albums
SET total_plays = total_plays - 1
WHERE name = OLD.album_name
AND artist_name = OLD.artist_name;
UPDATE genres
SET total_plays = total_plays - 1
WHERE id = (
SELECT genres
FROM artists
WHERE name_string = OLD.artist_name
);
RETURN OLD;
END;