Pol, first of all you need to find the real database error. The stuff after the first lines of the error you posted is not informative, it's just a tcl stacktrace. To find the real error do a 'tail -f /path/to/your/logfile', reproduce the error and then scroll up - above of 'Database operation "0or1row" failed' you should find some more interesting message from postgresql, which will tell you about the real problem here.
I believe that a more recent nspostgresql driver would show the relevant error conveniently in the browser.
To find out your postgresql version you could do for example:
$ psql yourdbname
yourdbname=# select version();
Looking at the plpgsql you posted I see an error with this non-legal sql:
insert into cads_categories
(category_id, short_name, p_description, p_domain_id);
Are you sure you created the cads_category__new successfully and you can execute it manually from psql?