"A B" <gentosaker@xxxxxxxxx> writes: > 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; > Can anyone help me spot the error? EXECUTE doesn't set FOUND. I think you'd be well advised to rethink your table layout so you don't need so much dynamic SQL. The above is going to suck on both performance and readability grounds, and it doesn't look like it's accomplishing anything you couldn't do by combining all the Rating tables into one table with an extra key column. regards, tom lane