Answers for "postgres trigger on insert or update"

SQL
8

example of trigger in postgresql

-- Trigger to update donatiom count in donor table whenever
-- A new donation is made by that person

CREATE or REPLACE FUNCTION increase_count()
RETURNS TRIGGER
AS
$$
BEGIN
	UPDATE donor SET dcount = dcount + 1 WHERE did = NEW.did;
END
$$
LANGUAGE plpgsql;



CREATE TRIGGER update_donation_count AFTER INSERT ON donation
FOR EACH ROW
EXECUTE PROCEDURE increase_count();
Posted by: Guest on May-19-2020
1

trigger in postgresql to change incoming entry

CREATE or REPLACE FUNCTION func()
RETURNS TRIGGER
AS $$
BEGIN
NEW.columnname = 0;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;

-- Statement to make trigger to execute above code --
CREATE TRIGGER change_incoming BEFORE INSERT on Tablename 
FOR EACH ROW EXECUTE PROCEDURE func();
Posted by: Guest on May-19-2020

Code answers related to "postgres trigger on insert or update"

Code answers related to "SQL"

Browse Popular Code Answers by Language