Dynamic Log tigger (plpgsql)

From: Noah Heusser <noah(at)heussers(dot)ch>
To: pgsql-general(at)postgresql(dot)org
Subject: Dynamic Log tigger (plpgsql)
Date: 2007-06-16 11:26:57
Message-ID: 4673C901.2000806@heussers.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

I want to implement a trigger-function witch can fill the following table.
Each data manipulation (INSERT, UPDATE or DELETE) gets logged.
The function should work as trigger on diffrent tables.

CREATE TABLE logtable (
operation CHAR(6) CHECK (change_type IN ('DELETE', 'INSERT', 'UPDATE')),
tablename VARCHAR,
rowid INTEGER, -
touched_columns VARCHAR[]
);

My Problem is in the last Column (touched_columns).
If it was an UPDATE Operation, I just need to know witch columns changed. (I am not iterrestet in the old or new value)
=> IF OLD.columnName != NEW.columnName, it has changed.

My Question:
How can I do "OLD.columnName != NEW.columnName" if I don't know what the
columnNames are at Compile Time?
I have the columnName in a variable.

Thx for help.
Noah

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Allison 2007-06-16 11:36:08 Re: Using the GPU
Previous Message Tom Allison 2007-06-16 03:17:37 Re: DeadLocks..., DeadLocks...