Referencing columns of the fly in triggers - Mailing list pgsql-general

From James F
Subject Referencing columns of the fly in triggers
Date
Msg-id 002f01c29fcd$074f1310$3b0010ac@jfreezexp
Whole thread Raw
Responses Re: Referencing columns of the fly in triggers
List pgsql-general

I would like to know if there is any way to create a common ON UPDATE trigger function that can be called from any table and be able to figure out which field(s) changed. The difficulty is being able to reference at run time the column names of that table, short of hard-coding all of them. The new and old records allow you to reference the columns, but only if you already know the name of the column. Is there nothing equivalent to new[column_index] that would allow me to iterate through the columns without knowing beforehand the column names? And then, given a certain column index, to reference the name of that column?

The goal of this trigger is to log all UPDATES to an audit log table, so the table name, column name, and new column value are all needed to write to the change log. Is there a better way of doing this?

thanks for your help.

James F

pgsql-general by date:

Previous
From: "Robert Fitzpatrick"
Date:
Subject: Field sizes and structure
Next
From: Mike Mascari
Date:
Subject: Re: Is NULL equal to NULL or not?