I want to create a plpgsql function that will be called by a BEFORE INSERT trigger. This function is updating a column based on value from another column.
Here is the code:
CREATE OR REPLACE FUNCTION Xupd_cat_prop()
RETURNS TRIGGER
AS
$$
DECLARE categ_prop varchar;
BEGIN
kateg_prop := CASE
WHEN new.cat_tarif = 'domestic_1' OR new.cat_tarif = 'domestic_2' THEN new.class = 'DOM'
WHEN new.cat_tarif = 'nondomestic_1' THEN new.class = 'NONDOM'
WHEN new.cat_tarif = 'industry' THEN new.class = 'IND'
END;
RETURN new;
END;
$$
LANGUAGE plpgsql;
But this doesn't work. I am using Postgres 16.
The error is somewhere with the WHEN clause.