Referencing columns of the fly in triggers

From: "James F" <nospam_james(at)hcjb(dot)org(dot)ec>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Referencing columns of the fly in triggers
Date: 2002-12-09 21:50:44
Message-ID: 002f01c29fcd$074f1310$3b0010ac@jfreezexp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message scott.marlowe 2002-12-09 22:08:08 Re: Is NULL equal to NULL or not?
Previous Message Robert Fitzpatrick 2002-12-09 21:44:02 Field sizes and structure