Adam, I think you are running into the same problem with overly large
procedure definitions that's been discussed here recently. In 6.5.*
it's not safe to create a procedure def that's more than 2700 bytes.
Workaround: split your code into smaller functions.
7.0 will be better...
regards, tom lane