Thanks. You suggestion helped me to find a solution! DECLARE ... query text; BEGIN .... query := query :='SET SESSION ROLE ' || wishedrole; EXECUTE query; ......