[
https://issues.apache.org/jira/browse/CALCITE-1199?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15240799#comment-15240799
]
Julian Hyde commented on CALCITE-1199:
--------------------------------------
I quickly read the spec and it appears that CHAR is not to be trimmed when
converting to VARCHAR. From 6.13 <cast specification>:
{quote}
c) If SD is fixed-length character string, variable-length character string,
or large object character string, then
Case:
i) If the length in characters of SV is less than or equal to MLTD, then TV is
SV.
ii) If the length in characters of SV is larger than MLTD, then TV is the first
MLTD characters of SV. If any of the remaining characters of SV are non-<space>
characters, then a completion condition is raised: warning — string data, right
truncation.
{quote}
So it looks if current behavior is incorrect. However, I do recall a bug with
{quote}
insert into t2 select ' ' as twoSpace from t union all select ' ' as
threeSpace from t
{quote}
where the target column in t2 is a varchar(4). We should make sure not to break
that again. The twoSpace value must not be padded to three spaces when it is
implicitly converted from CHAR(2) to CHAR(3). IIRC it should be converted
directly to a varchar(4).
> Incorrect trimming of CHAR when performing cast to VARCHAR
> ----------------------------------------------------------
>
> Key: CALCITE-1199
> URL: https://issues.apache.org/jira/browse/CALCITE-1199
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Jesus Camacho Rodriguez
> Assignee: Jesus Camacho Rodriguez
>
> Assume the value ' ' with type CHAR(1) that needs to be cast to VARCHAR(10).
> The method {{makeCast}} (line 488 in RexBuilder.java) trims spaces on the
> right hand side of the CHAR value, but this seems incorrect as it could lead
> to incorrect results.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)