Apply postgreSQL trigger to existing rows in database Apply postgreSQL trigger to existing rows in database postgresql postgresql

Apply postgreSQL trigger to existing rows in database


Since the table is small, just do a dummy update of the entire table:

update pg_rocks_post set title=title;

And let the trigger do its thing.


Normally triggers would run on a table on BEFORE or AFTER an insert, update or delete of a row. There are several options that allow you to decide on when to call the trigger.

Updating the row currently being inserted before insert would be a typical way to use a trigger. Then it is just a matter of creating a trigger on the actual table:

CREATE TRIGGER trig_title_upweight_trigger  BEFORE INSERT OR UPDATE  ON pg_rocks_post  FOR EACH ROW  EXECUTE PROCEDURE title_upweight_trigger();