SET SESSION AUTHORIZATION 'dba'; CREATE TABLE ganntinfo ( id integer NOT NULL, seq smallint, category character varying(20), name character varying(40) -- PRIMARY KEY( id, seq ) ); CREATE TABLE taskshead ( id integer PRIMARY KEY, category character varying(20), subject character varying(40), customer character varying(40), description character varying(400) ); CREATE VIEW tasks ( id, seq, category, name, subject, customer, description ) AS SELECT g.id, g.seq, g.category, g.name, h.subject, h.customer, h.description FROM taskshead h LEFT OUTER JOIN ganntinfo g USING ( id, category ) -- WHERE g.seq = 0 AND g.id = h.id AND g.category = h.category ; CREATE RULE insert_tasks2taskshead AS ON INSERT TO tasks WHERE NEW.seq = 0 DO ( insert into taskshead values ( NEW.id, NEW.category, NEW.subject, NEW.customer, NEW.description ); ) ; CREATE RULE insert_tasks2ganntinfo AS ON INSERT TO tasks DO INSTEAD ( insert into ganntinfo values ( NEW.id, NEW.seq, NEW.category, NEW.name ); ) ; CREATE RULE update_tasks2taskshead AS ON UPDATE TO tasks WHERE NEW.seq = 0 DO NOTHING ; CREATE RULE update_tasks2ganntinfo AS ON UPDATE TO tasks DO INSTEAD ( update ganntinfo set id = NEW.id, seq = NEW.seq, category = NEW.category, name = NEW.name -- WHERE id = NEW.id AND seq = NEW.seq AND category = NEW.category ; ) ;