Testing if a Column Exists in a NEW record of a Trigger Function

Поиск
Список
Период
Сортировка
От Simon ...
Тема Testing if a Column Exists in a NEW record of a Trigger Function
Дата
Msg-id SNT149-W446BFBDC8079E84B9D632D91B60@phx.gbl
обсуждение исходный текст
Ответы Re: Testing if a Column Exists in a NEW record of a Trigger Function  (Sameer Kumar <sameer.kumar@ashnik.com>)
Re: Testing if a Column Exists in a NEW record of a Trigger Function  (Sergey Konoplev <gray.ru@gmail.com>)
Список pgsql-novice
Dear List,

As part of the Audit process in my psql database, I have a standard set of columns "InsertBy", "InsertTime", "LastUpdateBy" & "LastUpdateTme".  I use a standard Trigger function [listed below] to ensure the correct details are added to each record. 
However, on some data tables where data is only imported and not updated, the "Update" columns are not required.

As such, is there a way to test the NEW record variable to see if the column "LastUpdateBy" exists?   I could not find any information in the manual to describe how this might be done.

Thanks
Simon

CREATE OR REPLACE FUNCTION "Security"."InsertStamp"() RETURNS trigger as $InsertStamp$
    DECLARE
               UserID integer;
    BEGIN
                SELECT "IDUser" INTO UserID FROM "Security"."User" WHERE "Username" = current_user;
                NEW."InsertBy" := UserID;
                NEW."InsertTime" := current_timestamp;
                NEW."LastUpdateBy" := UserID;
                NEW."LastUpdateTime" := current_timestamp;
                RETURN NEW;
    END;
$InsertStamp$ LANGUAGE plpgsql STABLE SECURITY DEFINER;

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Pagett, Lacey"
Дата:
Сообщение: Re: 0FATAL: too many connections for database
Следующее
От: Sameer Kumar
Дата:
Сообщение: Re: Testing if a Column Exists in a NEW record of a Trigger Function