Re: "OLD." || myColumnNameVar (How to generically access columns in a trigger's OLD or NEW records)

From: ivan_14_32 <ivan_14_32(at)mail(dot)ru>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: "OLD." || myColumnNameVar (How to generically access columns in a trigger's OLD or NEW records)
Date: 2011-08-24 18:03:20
Message-ID: 4E553CE8.5080506@mail.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

01.05.2011 12:58, Basil Bourque wrote:
> Hoorah! I was able to complete my single PL/pgSQL function to create history records tracking individual field value changes generically for all my tables. Some developers call this an "audit trail", though an accountant might say otherwise.
>
I made auditing based on triggers like aforementioned. And now I need
fill audit table with already presented data. But there is a problem.

within trigger
EXECUTE 'SELECT ($1)."name"::text' INTO newVal USING NEW;
works fine

but function (table "decor" has field "name")
CREATE OR REPLACE FUNCTION "odb_InitLog"()
RETURNS void AS
DECLARE
obj record;
BEGIN
FOR obj IN (SELECT * FROM "decor") LOOP
EXECUTE 'SELECT ($1)."name"::text' INTO newVal USING obj;
END LOOP;
END;
doesn't work - ERROR: could not identify column "name" in record data type

Why?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-08-24 18:19:26 Re: Feature Request: DDL + RegExp - definitions
Previous Message John R Pierce 2011-08-24 17:50:58 Re: postgresql server crash on windows 7 when using plpython