CREATE TABLE Part (
	Partkey INTEGER,
	Name CHAR(55),
	Mfgr CHAR(25),
	Brand CHAR(10),
	Type CHAR(25),
	Size INTEGER,
	Container CHAR(10),
	Retailprice NUMERIC(12,2),
	Comment CHAR(23),
	PRIMARY KEY (Partkey)
);
CREATE FUNCTION calcula_retailprice() RETURNS opaque AS
 'DECLARE
codigo INTEGER;
BEGIN
	codigo:=NEW.Partkey;
	UPDATE part SET retailprice=((90000+((part.partkey/10)%20001)+100*(part.partkey%1000))/100)
	WHERE Partkey=codigo;
  	RETURN NULL;
END;'
LANGUAGE 'plpgsql';
CREATE TRIGGER trigger_retailprice 
AFTER INSERT ON part FOR EACH ROW EXECUTE PROCEDURE calcula_retailprice();
