I have before insert trigger in postgres
CREATE OR REPLACE FUNCTION add_requestdate() RETURNS TRIGGER AS $$
DECLARE
BEGIN
new.requestdate := now();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER addrequestdate
BEFORE INSERT ON requests FOR EACH ROW EXECUTE PROCEDURE add_requestdate ();
But it doesn't work! I have solution that works...
CREATE OR REPLACE FUNCTION add_requestdate() RETURNS TRIGGER AS $$
DECLARE
BEGIN
UPDATE requests SET requestdate=now() WHERE id=NEW.id;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER addrequestdate
BEFORE INSERT ON requests FOR EACH ROW EXECUTE PROCEDURE add_requestdate ();
I have only one question. Why new.requestdate := now(); doesn't work?
requests.idis not unique - on other rows with the sameid. Isidunique? Are there additional other triggers involved?