I have the below user table
Column | Type | Modifiers
-----------+--------------------------+-------------------------------------------------------
id | integer | not null default nextval('accounts_id_seq'::regclass)
username | character varying(40) |
email | character varying(40) |
password | character varying |
join_date | timestamp with time zone | default now()
xp | integer | default 0
level | integer | default 1
provider | character varying |
is_admin | boolean | default false
I'm trying to create a trigger which looks at the user xp INTEGER and updates his level based on the given xp
this is my below function and necessary trigger
CREATE OR REPLACE FUNCTION set_user_level() RETURNS TRIGGER AS $level$
BEGIN
CASE
WHEN NEW.xp BETWEEN 100 AND 200 THEN
NEW.level = 2;
WHEN NEW.xp BETWEEN 200 AND 400 THEN
NEW.level = 3;
ELSE
NEW.level = 1;
END CASE;
RETURN NEW;
END;
$level$ LANGUAGE plpgsql;
CREATE TRIGGER set_user_level AFTER UPDATE ON account FOR EACH ROW EXECUTE PROCEDURE set_user_level();
However , whenever i update the user xp . The user level still stays at 1. Is there something wrong with my syntax? I pretty much used the same syntax as specified in the docs.