"Christoph Zwerschke" <c...@online.de> wrote: > ascii(cast(' ' as char(1))), > ascii(cast(' ' as char)) > both give 0. > > I think this quirk should be fixed or at least mentioned in the > documentation of ascii().
The problem is not in ascii(), but in casting from char to text. We have only one version of ascii() in default; ascii(text). So, if you use ascii( ' '::char(1) ), it is actually handled as ascii( ' '::char(1)::text ). Traling spaces were removed during the cast to text. You could have the same result with other databases if you define a char version of ascii(). =# CREATE FUNCTION ascii(bpchar) RETURNS integer AS 'ascii' LANGUAGE internal; =# SELECT ascii(cast(' ' as char(1))); ascii ------- 32 (1 row) Do you know how the SQL standard mention the behavior? IMHO, postgres' behavior is more reasonable because length(' '::char(1)) is 0. Regards, --- Takahiro Itagaki NTT Open Source Software Center -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs