A stored procedure is a precompiled set of SQL statements stored and executed on a PostgreSQL database server.

-- Create function that can update "updated_at"
CREATE OR REPLACE FUNCTION trigger_set_timestamp()
RETURNS TRIGGER AS $$
BEGIN
	NEW.updated_at = NOW();
	RETURN NEW;
END;
$$ LANGUAGE plpgsql;

-- Bind the function to a table, so their "updated_at" can be updated automatically
CREATE TRIGGER set_timestamp
BEFORE UPDATE ON keyvalue
FOR EACH ROW
EXECUTE PROCEDURE trigger_set_timestamp();

References