2
votes

I have created below trigger and function for update on function where I want to exclude trigger execution when there are update on two columns 'frm' and 'upto' which are of type "timestamp without time zone"

In trigger function I am checking for updates on these two columns

CREATE OR REPLACE FUNCTION ff() RETURNS TRIGGER AS $$
BEGIN 
    if((old."frm" == New."frm") and (old."upto" == New."upto") ) then
        insert into TG_TABLE_NAME (select * from inserted );
        New."from" := old."from"; 
        NEW."upto" := current_timestamp;
        RETURN NEW; 
    END IF;
    RETURN NULL;
 END $$ LANGUAGE plpgsql;

create trigger update_trig2 after update on dd 
for each row execute procedure ff();`

After running update query i am getting below error in postgreSQL

ERROR: operator does not exist: timestamp without time zone == timestamp without time zone

1
The comparison operator is '=' , not '==' .wildplasser
As I remember: plsql language initially designed by Oracle based on Ada language which based on Pascal language. So as you can see the assignment operator is := and the equality operator is = (however the inequality operator could be both <> and !=)Abelisto
Thanks that works now but having below error ERROR: relation "tg_table_name" does not exist LINE 1: insert into TG_TABLE_NAME (select * from inserted ) Could you please tell if TG_TABLE_NAME is not a corrrect way to refer table which is invoking trigger??user2250572

1 Answers

4
votes

The comparison operator is = in SQL and PL/pgSQL.

So you need to replace == with =