How to select number of affected rows to variable in function?
create or replace function test()
returns void as $$
declare
    v_cnt numeric;
begin
    v_cnt := 0;

        update tbl set col1 = true where col2 = false;
        GET DIAGNOSTICS v_cnt = ROW_COUNT;

        if v_cnt &gt; 1 then
           RAISE EXCEPTION 'more than one row affected --&gt; %', v_cnt; 
        end if;
end;
$$ language plpgsql;