>
> select count(*) into cnt from <tablename> where new.<key> = key;
> if (cnt>0) then
> delete from <tablename> where key = new.<key>
> end if
>
Just looked at this, and this is not actually what you wanted. If you do
not want to replace the old row, do something along the lines
RAISE EXCEPTION ''Duplicate entry''
which will abort the insert. It's all in the manual.
Adriaan