Nelio Alves Pereira Filho <nelio@ifx.com.br> writes:
> create trigger set_counter after insert or update on nivel
> for each row execute procedure set_counter();
> The problem is that after I insert something, count value is still -1,
> not 0!
You want a BEFORE trigger, not an AFTER trigger. AFTER is too late
to affect the contents of the stored row.
regards, tom lane