I have been chasing Domingo Alvarez Duarte's report of funny behavior
when assigning an empty string to a "char" variable in plpgsql. What
it comes down to is that text-to-char conversion does not behave very
well for zero-length input. charin() returns a null character, leading
to the following bizarreness:
regression=# select 'z' || (''::"char") || 'q';?column?
----------z
(1 row)
regression=# select length('z' || (''::"char") || 'q');length
-------- 3
(1 row)
The concatenation result is 'z\0q', which doesn't print nicely :-(.
text_char() produces a completely random result, eg:
regression=# select ''::text::"char";?column?
----------~
(1 row)
and could even coredump in the worst case, since it tries to fetch the
first character of the text input no matter whether there is one or not.
I propose that both of these operations should return a space character
for an empty input string. This is by analogy to space-padding as you'd
get with char(1). Any objections?
regards, tom lane