I'm trying to write a function for a trigger that checks if the date in a new entry in a relation is bigger than the entry in an other relation. If that is the case, I want to update the date value in my new relation to the date value in my other relation:
create or replace function curDate()
returns trigger as $$
Begin
if (new.date >= (select date from other where new.name = other.name )) then
set new.date = (select date from playlist where new.name = other.name );
end if;
end; $$ language plpgsql;
I get a syntax error on:set new.date = (select date from playlist where new.name = other.name )
However, this works fine:
create or replace function curDate()
returns trigger as $$
declare dateVar date;
Begin
dateVar := (select date from other where new.name = other.name);
if (new.datum >= dateVar) then
new.datum = dateVar;
end if;
end; $$ language plpgsql;
Why is that?