I'm creating a trigger function that must populate a field called "numero_cip". This field must be fill just one time after a "INSERT ROW", because this field is a join from: "BR" + ID FIELD + SUFIXO FIELD.
So, i'm trying to create this trigger function:
CREATE OR REPLACE FUNCTION numeradora_cip()
RETURNS trigger AS $$
DECLARE
sufixo varchar(2);
numero_cip varchar(60);
BEGIN
sufixo := select p.sufixo from produto p where p.id = NEW.id_produto;
NEW.numero_cip = select 'BR' || lpad(NEW.id, 11, '0') || sufixo;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
But i got the error:
ERROR: syntax error at or near "select"
LINE 7: sufixo := select p.sufixo from produto p where p.id = NE...
PS: This is my first time creating a trigger function.