ページ構成は、存在する部品の一覧ページと、指定部品についての詳細ページから成るとする。
CREATE TABLE p06_parts_history ( type varchar(30), id int, date timestamp, manager varchar(16), comment varchar(200) ); -- ノハ・ニ。シ・ヨ・チ CREATE TABLE p06_parts AS SELECT * FROM p06_parts_history;
CREATE FUNCTION p06_parts_tri() RETURNS TRIGGER AS ' DECLARE BEGIN DELETE FROM p06_parts WHERE type=NEW.type and id=NEW.id; INSERT INTO p06_parts SELECT * FROM p06_parts_history WHERE type=NEW.type and id=NEW.id and date IN (SELECT max(date) FROM p06_parts_history WHERE type=NEW.type and id=NEW.id); RETURN NEW; END; ' LANGUAGE 'PLpgSQL'; CREATE FUNCTION p06_parts_delete_tri() RETURNS TRIGGER AS ' DECLARE BEGIN DELETE FROM p06_parts WHERE type=OLD.type and id=OLD.id; INSERT INTO p06_parts SELECT * FROM p06_parts_history WHERE type=OLD.type and id=OLD.id and date IN (SELECT max(date) FROM p06_parts_history WHERE type=OLD.type and id=OLD.id); RETURN OLD; END; ' LANGUAGE 'PLpgSQL'; -- ・ネ・ャトチ CREATE TRIGGER p06_parts_change AFTER insert OR update ON p06_parts_history FOR EACH ROW execute procedure p06_parts_tri(); CREATE TRIGGER p06_parts_delete AFTER delete ON p06_parts_history FOR EACH ROW execute procedure p06_parts_delete_tri();