CREATE FUNCTION ar_artist() RETURNS trigger AS $$ BEGIN INSERT INTO archive_artist (artistid, name) VALUES (OLD.artistid, OLD.name); RETURN OLD; END; $$ LANGUAGE 'plpgsql';
CREATE TRIGGER archiveArtist BEFORE DELETE ON artist FOR EACH ROW EXECUTE PROCEDURE ar_artist();
Thank you
Thank you so much! Very useful!
exactly what i needed , thank you very much
This really helped. Thank you!
i was looking for this , clear explanation, thank you!!!!
Exactly what I needed--thanks 👏!
thank you clear explanation.
For me using postgres13, I have to return new for update to happen. Otherwise despite the insert to archive working, the record will stay as it was.
I forgot to thank you for the great tutorial you have made. I wish you could do another shorter one with faster pace.
CREATE FUNCTION ar_artist()
RETURNS trigger AS
$$
BEGIN
INSERT INTO archive_artist (artistid, name)
VALUES (OLD.artistid, OLD.name);
RETURN OLD;
END;
$$
LANGUAGE 'plpgsql';
CREATE TRIGGER archiveArtist
BEFORE DELETE ON artist
FOR EACH ROW
EXECUTE PROCEDURE ar_artist();