This second problem - casting - is probably brought about by changes
from PG 6.5 to PG 7.0. Try casting the non-varchar like this:
"foo::varchar"
and see if that fixes the problem.
And, yes, the syntax for if doesn't include a shorthand "elseif" or
"elsif", you have to write them out as a string of nested "if then
else end if" statements in Pl/pgSQL.
I may have time to incorporate your first fix into CVS this weekend -
no promises, though!