I wrote:
> AFAICS your patch does not avoid the fact that the function will throw
> error on a zero input.
Oh, no, scratch that --- I was thinking that you were applying the
function directly to pg_class.reltablespace, but you're applying it to
pg_tablespace.oid, so the issue should not arise.
regards, tom lane