From the course: Advanced PostgreSQL
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Creating a row-level, after update trigger - PostgreSQL Tutorial
From the course: Advanced PostgreSQL
Creating a row-level, after update trigger
In this movie, we'll see how we can create a row level after update trigger. Now, in order to set up our trigger, I'm going to create a new table called employee_salary_logs into which we log records each time we perform an update on the employee table. So we have the ID, first name, last name, the old salary, the new incremented salary, and the date the salary was actually incremented. That is the incremented_on field. The next step is to set up the trigger function. Observe that the way I've defined this trigger function is a little different, but the objective is the same. This function will be fired when an update operation occurs on the table. So I use create or replace function. The name of the function is employee salary update function. This returns a trigger. The language that I've used to specify this trigger is plpgsql and I use the as keyword and then define the function itself. Notice that the function begins with the double dollar sign. And if you scroll down, you'll see…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.