I’m new to triggers.
I have a function that I use to check if a password is valid that returns a boolean value. Is it possible to trigger a trigger only if the value is true? (This would update the last_login_time based on successful password checking).
PS I’m using PostgreSQL 9.0.4
Is it possible to write such trigger?
No, but you can check the password again in your trigger and execute the logic needed if it validates. Triggers can fire only after or before INSERT, UPDATE, or DELETE, and either for each row or for the whole statement. There’s no way to conditionally fire a trigger of certain type AFAIK.
Edit:
There is a WHEN clause in CREATE TRIGGER statement that allows one to specify conditions when the trigger should fire, but then you’d have to check the validation in the condition which is equivalent to what i posted above, only covered with syntactic sugar.
Still it’s probably something that should be done in stored procedure or outside of DB.