In PostgreSQL 9.5, I have tables with columns in the form
prefix_last_modified timestamp without time zone NOT NULL DEFAULT (clock_timestamp() AT TIME ZONE 'UTC')
I was looking for a way to set the last modified value automatically updated at each update of the rows, and I found this nice post that defined the function:
CREATE OR REPLACE FUNCTION update_modified_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.modified = now();
RETURN NEW;
END;
$$ language 'plpgsql';
Now, I'd like to know if there is any way to pass the column name to the PostgreSQL function and to execute it to the NEW
row? E.g.
CREATE OR REPLACE FUNCTION update_modified_column(varchar column)
RETURNS TRIGGER AS $$
BEGIN
NEW.column = now();
RETURN NEW;
END;
$$ language 'plpgsql';