Skip to Content
Mastering PostgreSQL 12 - Third Edition
book

Mastering PostgreSQL 12 - Third Edition

by Hans-Jürgen Schönig
November 2019
Beginner to intermediate
470 pages
11h 59m
English
Packt Publishing
Content preview from Mastering PostgreSQL 12 - Third Edition

Writing triggers in PL/pgSQL

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 that is called by the trigger can then modify the data that's changed in your table, or simply perform a necessary operation.

In PostgreSQL, triggers have become more powerful over the years, and they 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering PostgreSQL 11 - Second Edition

Mastering PostgreSQL 11 - Second Edition

Hans-Jürgen Schönig
Learning PostgreSQL 11 - Third Edition

Learning PostgreSQL 11 - Third Edition

Christopher Travers, Andrey Volkov
PostgreSQL Server Programming - Second Edition

PostgreSQL Server Programming - Second Edition

Usama Dar, Hannu Krosing, Jim Mlodgenski, Kirk Roybal

Publisher Resources

ISBN: 9781838988821Supplemental Content