Trigger updating column Gratis teensex chat

-- Paul Fleming At best you can say that one job may be more secure than another, but total job security is an illusion.-- Rod at work Check out these links on how to get faster and more accurate answers: Forum Etiquette: How to post data/code on a forum to get the best help Need an Answer? # \d users Table "public.users" Column | Type | Modifiers ------------------ ------------------- ---------------------------------------------------- id | integer | not null default nextval('users_id_seq'::regclass) username | character varying | not null password | character varying | not null password_changed | date | default now() Indexes: "users_username_key" UNIQUE CONSTRAINT, btree (username) Triggers: trigger_password_changed BEFORE UPDATE ON users FOR EACH ROW EXECUTE PROCEDURE List of functions -[ RECORD 1 ]------- ----------------------------------------- Schema | public Name | password_changed Result data type | trigger Argument data types | Type | trigger Security | invoker Volatility | volatile Owner | postgres Language | plpgsql Source code | | BEGIN | IF NEW.password != OLD.password THEN | NEW.password_changed := current_date; | END IF; | RETURN NEW; | END; Because the trigger is defined within the database it will survive any normal backup and restore process unaffected.

If you need to determine if the value is changing, you'll still need to code comparison logic for :old and :new values.

We have a simple database of usernames and (encrypted) passwords with the following definition: Rather than tackling each of these independently, using a trigger we can address them all at the same time, and all from within the database.

We create our trigger function using PL/pg SQL - which comes built in in Postgre SQL 9.0 and later, and can be installed as an add-on for earlier versions.

It works, but it won't tell you if the value changed, only that the column is being updated (even if the update doesn't change the value).

Many applications update all of the columns in a table -- setting them to their old value, rather then trying to figure out exactly which columns have been updated by the client. create or replace trigger test_trigger 2 after update of x,y on test 3 for each row 4 begin 5 if updating( 'X' ) then 6 dbms_output.put_line( 'X is being updated' ); 7 end if; 8 9 if updating( 'Y' ) then 10 dbms_output.put_line( 'Y is being updated' ); 11 end if; 12 end; 13 / Trigger created.

Leave a Reply