
DROP TABLE version_test;
CREATE TABLE version_test (
        nome		text,
	username	char(10),	-- user name
	version	timestamp	-- last update
);

drop function f_version();
create function f_version() returns opaque as '
begin
	new.version:= current_timestamp;
	new.username:= current_user;
 	return new;
end;
' language 'plpgsql';

CREATE TRIGGER t_version
	BEFORE INSERT OR UPDATE ON version_test
	FOR EACH ROW 
	EXECUTE PROCEDURE f_version();

INSERT INTO version_test VALUES ('jose','marco','1998-12-31 12:30:00');
INSERT INTO version_test VALUES ('miriam');
update version_test set username='jose';

SELECT * FROM version_test;
