Is it possible to see the last entry into a table that was triggered on?
For instance, I have a table called "users" and a table called "log". I want to write to "log" the userid that was last written to "users" so each time a user is created, it writes the userid to a log.
I create a trigger on users with a function like the one below...
CREATE OR REPLACE FUNCTION process_learner_creater() RETURNS TRIGGER AS $log$ BEGIN IF (TG_OP = 'INSERT') THEN INSERT INTO log SELECT userid from users; RETURN NULL; END IF; RETURN NULL; END; $log$ LANGUAGE plpgsql;
So when an insert is fired onto the users table it will return the userid from users, the problem is I don't know what was the last user to be added so this function will not work...
Is there a way to say...
INSERT INTO log SELECT <> from users;
This field in users would be a serial field so would auto-increment (and not be part of the the SQL script in the insert as this would be auto-assigned).