I have problem when create function for trigger. I want to UPDATE inserted value BEFORE INSERT data to DB. My code look like this:
CREATE OR REPLACE FUNCTION test_func() RETURNS TRIGGER AS $$ DECLARE cnt INTEGER; BEGIN cnt := COUNT(*) FROM sample_tbl WHERE id = NEW.id AND created_date = NEW.created_date; NEW.current_order := cnt + 1; // I want to set value of sample_tbl.current_order automatically END $$ LANGUAGE plpgsql; CREATE TRIGGER test_trigger BEFORE INSERT ON test_tbl FOR EACH ROW EXECUTE PROCEDURE test_func(); I inserted data then IDE said: control reached end of trigger procedure without RETURN Where: PL/pgSQL function test_func()