Re: Updating - Mailing list pgsql-general

From Harvey, Allan AC
Subject Re: Updating
Date
Msg-id E97A5BB7699CAD48BE2711E71247116502F8942C@ntlmsg03.onesteel.com
Whole thread Raw
In response to Re: Updating  (Bob Pawley <rjpawley@shaw.ca>)
List pgsql-general
> Would it be possible to get an example of such coding??

This trigger has an argument passed. When the trigger is "assigned"
I know whether the column is of type txt or float.

It uses the column name to determine what to do.

Hope this helps Allan

create or replace function insert_if_diff() returns trigger as
$BODY$
declare
    r record;

begin
    for r in execute 'select ' || TG_ARGV[0] || ' from ' || TG_TABLE_NAME || '  order by dt desc limit 1;'
    loop
        if TG_ARGV[0] = 'value'
        then
            if new.value = r.value
            then
                return null;
            end if;
        end if;

        if TG_ARGV[0] = 'txt'
        then
            if new.txt = r.txt
            then
                return null;
            end if;
        end if;

        return new;
    end loop;

    return NEW;
end;

$BODY$
language plpgsql;


The material contained in this email may be confidential, privileged or copyrighted. If you are not the intended
recipient,use, disclosure or copying of this information is prohibited. If you have received this document in error,
pleaseadvise the sender and delete the document. Neither OneSteel nor the sender accept responsibility for any viruses
containedin this email or any attachments. 

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Updating
Next
From: tuanhoanganh
Date:
Subject: array function problem