Server-side code is especially popular if you want to react to certain events that are happening in the database. A trigger allows you to call a function if an INSERT, UPDATE, DELETE, or TRUNCATE clause happens on a table. The function called by the trigger can then modify the data that's changed in your table or simply perform some necessary operation.
In PostgreSQL, triggers have become more powerful over the years and now provide a rich set of features:
test=# \h CREATE TRIGGERCommand: CREATE TRIGGERDescription: define a new triggerSyntax:CREATE [ CONSTRAINT ] TRIGGER name { BEFORE | AFTER | INSTEAD OF } { event [ OR ... ] } ON table_name [ FROM referenced_table_name ] [ NOT DEFERRABLE | [ DEFERRABLE ] [ INITIALLY ...