"Joel Jacobson" <j...@compiler.org> writes: > When a text string of a single space character is casted to a character, > I would assume the result to be, a space character, > but for some reason it's the null character.
This is because of the weird semantics of char(N). chr(32) produces a TEXT value containing one space, which you then cast to CHAR(1), making the trailing space semantically insignificant. But the ascii() function requires a TEXT argument, so we immediately cast the string back to TEXT, and that cast is defined to strip any trailing spaces. Thus, what gets delivered to ascii() is an empty TEXT string, causing it to return 0. If you'd just done ascii(chr(c)), you'd have gotten c. regards, tom lane