January 2019
Intermediate to advanced
520 pages
14h 32m
English
This SQL file contains two statements. The first is the diesel_manage_updated_at function, whichcreates a trigger for a table to call the diesel_set_updated_at function for each row update:
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$BEGIN EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);END;$$ LANGUAGE plpgsql;
This function only executes the CREATE TRIGGER statement for a table you provided with the _tbl argument.
The second function is diesel_set_updated_at, which updates the updated_at column with the current timestamp if the processed row has changed:
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS ...
Read now
Unlock full access