I'm trying to create a Postgres trigger to ensure after a column's value has been set, it cannot be updated (basically make it readonly). So far I've come up with the following draft trigger.
1) First, am I on the correct track?
2) Is there value in returning
3) Must I preface
CREATE FUNCTION check_id_change() RETURNS TRIGGER AS $$ BEGIN IF OLD.original_id <> NEW.original_id THEN RAISE EXCEPTION 'cannot change original_id'; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql; CREATE TRIGGER client_update_trigger AFTER UPDATE ON client FOR EACH ROW EXECUTE PROCEDURE check_id_change();