DROP TABLE t;

CREATE TABLE t
( id SERIAL PRIMARY KEY,
  data TEXT NOT NULL,
  isLast BOOLEAN NOT NULL DEFAULT TRUE
);

CREATE RULE t_update AS
ON INSERT TO t DO ALSO
UPDATE t SET isLast=FALSE 
WHERE id<new.id;

INSERT INTO t(data) VALUES('one');
SELECT last_value FROM t_id_seq;

INSERT INTO t(data) VALUES('two');
SELECT last_value FROM t_id_seq;

INSERT INTO t(data) VALUES('three');
SELECT last_value FROM t_id_seq;

INSERT INTO t(data) VALUES('four');
SELECT last_value FROM t_id_seq;

SELECT * FROM t;
