I am using triggers if any update on my table - 'test'. I have created trigger as mentioned below.
create table log_changes(one integer primary key not null, old_three text, new_three text, old_four text, new_four text, old_five text, new_five text, update_time timestamp DEFAULT Now());
create or replace function log_changes()
returns trigger as
$$
BEGIN
insert into log_changes(one,old_three , new_three , old_four , new_four , old_five , new_five )
values
(one, old.old_three , new.new_three , old.old_four , new.new_four , old.old_five , new.new_five);
return new;
END;
$$ language plpgsql
create trigger update_log_table
after update on test
for each row execute procedure log_changes();
update test
set three = 'aa' and four = 'aa' and five = 'aa'
where one = 1 and two = 'a';
After I am executing update query, I am getting following error
ERROR: invalid input syntax for type boolean: "aa"
LINE 1: update test set three = 'aa' and four = 'aa' and five = 'aa'...
^
SQL state: 22P02
Character: 25
=================================================================
Another Error ::
Trigger Function :
create or replace function log_changes()
returns trigger as
$$
BEGIN
insert into log_changes(one,old_three , new_three , old_four , new_four , old_five , new_five ) values (new.one, old.old_three , new.new_three , old.old_four , new.new_four , old.old_five , new.new_five);
return new;
END;
$$ language plpgsql
After update, error is :
ERROR: record "old" has no field "old_three"
CONTEXT: SQL statement "insert into log_changes(one,old_three , new_three , old_four , new_four , old_five , new_five ) values (new.one, old.old_three , new.new_three , old.old_four , new.new_four , old.old_five , new.new_five)"
PL/pgSQL function log_changes() line 3 at SQL statement
SQL state: 42703