From: | Takahiro Itagaki <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp> |
---|---|
To: | "Christoph Zwerschke" <cito(at)online(dot)de> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #5438: Bug/quirk in ascii() function |
Date: | 2010-04-26 10:11:49 |
Message-ID: | 20100426191149.9282.52131E4D@oss.ntt.co.jp |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
"Christoph Zwerschke" <cito(at)online(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Christoph Zwerschke | 2010-04-26 12:00:29 | Re: BUG #5438: Bug/quirk in ascii() function |
Previous Message | Stefan Kirchev | 2010-04-26 08:16:19 | BUG #5439: Table crash after CLUSTER command |