Ok.
Are you sure you data migrated cleanly?
One problem you will have is upgrading from 8.1->8.3 since openacs 5.4 does not support 8.3.
YOu might want to upgrade to 5.5 before upgrading the database. According to the compatibility matrix, 5.5 will support pg 8.1.
I suspect the parent tree sortkey is NULL resulting in a NULL response from a plpgsql function causing the error.
Without more information on the inputs to the query it is hard to tell.