Hi. I run a function CREATE OR REPLACE FUNCTION addRating(tbl_ INTEGER,value_ INTEGER) RETURNS void AS $$ DECLARE tablename TEXT; fieldname TEXT; BEGIN tablename:='Rating_'||tbl_; fieldname:='val'; EXECUTE 'UPDATE '||tablename||' SET '||fieldname||'='||value_||' WHERE '||fieldname||'='||value_ ; IF NOT FOUND THEN EXECUTE 'INSERT INTO '||tablename||' ('||fieldname||') VALUES ('||value_||')'; END IF; END; $$ LANGUAGE plpgsql; The UPDATE command works fine (afterwards the table is updated) but it seems that it do the insert even if it do the update. I thought this was a correct useage of "FOUND" so that it either do the update or the insert, not both. Can anyone help me spot the error?