1

I am trying to implement a trigger function in PostgreSQL. I've written this trigger history function:

CREATE OR REPLACE FUNCTION history_update() 
RETURNS trigger AS

$$

    BEGIN

    INSERT INTO data_history (id, geom, origine, descrizione, img, created, created_by)

    VALUES (NEW.id, new.geom, new.origine, new.descrizione, new.img, current_timestamp, current_user);

    RETURN NEW;

END;

$$

LANGUAGE plpgsql;


 CREATE TRIGGER update_trigger
 AFTER UPDATE ON data   
 FOR EACH ROW EXECUTE PROCEDURE history_update();

Now I would like to add another column (called last_update) where to set the name of the column in which the value was updated.

For example if the updated value is in the column called "supporto", in the column "last_updated" I want to see the name of the same column with the updated value (called "supporto").

What if the updated values in the column are more than one?

possible suggestion

1) Insert in the row of the column "last_updated" more values

or

2) Insert as many column as the number of the column in the original table (for example "last_updated1", "last_updated2"...)

Any advice?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.