The task - to create a table, and set a trigger to mark a row as updated any time an insert or update is run against it.
CREATE TABLE employee
(
surname character varying(20) NOT NULL,
firstname character(20) NOT NULL,
dob date NOT NULL,
badgeid serial NOT NULL,
last_updated date NOT NULL,
CONSTRAINT u_badgeid UNIQUE (badgeid)
)
CREATE FUNCTION set_lastchg() RETURNS opaque AS
'BEGIN
NEW.last_updated = now();
RETURN NEW;
END;'
LANGUAGE 'plpgsql';
CREATE TRIGGER t_employee_1
BEFORE INSERT OR UPDATE
ON employee
FOR EACH ROW
EXECUTE PROCEDURE set_lastchg();
insert into employee (surname, firstname, dob ) values
('Jinkerson','Tim', date '1914-12-25')
All looks good!
Just somewhere to keep my notes while I'm playing.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment