EasyEnv
Engineering/Courses/Catalog/PostgreSQL/Functions and Triggers
PostgreSQL
IntermediateLesson 10 of 1435 min · hands-on

Functions and Triggers

Part of the PostgreSQL course

Every table in your schema has an updated_at column, and every one of them is wrong. Not always, just on the code paths where somebody forgot to set it: the admin script, the data fix you ran by hand, the third service that writes to the same table. The column is supposed to be a fact about the row, and instead it is a promise that every writer has to remember to keep. Postgres offers a way out.

A function is a named piece of logic you can call from SQL, like any built-in. A trigger is a function that Postgres runs automatically whenever a row is inserted, updated or deleted. Used precisely, they make certain mistakes impossible. Used loosely, they hide behaviour in a place nobody thinks to look. This lesson covers both halves of that. ...

Want to learn PostgreSQL Functions and Triggers in a real environment?

Click below, get a fresh Linux box with PostgreSQL ready to go, and work through Functions and Triggers hands-on with an AI tutor that knows your code.

Start this lessonFunctions and Triggers

What you'll learn

  • CREATE FUNCTION
  • LANGUAGE plpgsql
  • RETURNS
  • CREATE TRIGGER
  • BEFORE UPDATE
  • NEW and OLD
  • Updated_at pattern

Read this lesson in your language

All lessons in this course

14 lessons
  1. 1What is PostgreSQL20 min
  2. 2psql and First Commands25 min
  3. 3Creating Databases and Tables30 min
  4. 4Data Types25 min
  5. 5SELECT and WHERE30 min
  6. 6Joins35 min
  7. 7Aggregates and Grouping30 min
  8. 8Indexes35 min
  9. 9Transactions and Isolation35 min
  10. 10Functions and Triggers35 min
  11. 11JSONB and Arrays35 min
  12. 12EXPLAIN and Query Tuning35 min
  13. 13Backup and Restore25 min
  14. 14Capstone: Design a Schema60 min

Explore other courses

Functions and Triggers - PostgreSQL (English) | Engineering Courses