[
https://issues.apache.org/jira/browse/CALCITE-4861?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17433960#comment-17433960
]
Julian Hyde commented on CALCITE-4861:
--------------------------------------
[~nobigo], You describe two problems. In the first, Postgres and Calcite return
the same value; the difference is just a matter of display - I'm not sure
whether it's {{TO_CHAR}}, or {{ResultSet.getString}}, or something else in the
client doing the formatting. I don't feel strongly that Postgres is 'more
correct' in printing trailing zeroes.
In the second problem, this is another case of overflow of most significant
digits. Postgres and Calcite seem to agree that a DECIMAL(7, 7) can represent
numbers between -0.9999999 and +0.9999999.
> Optimisation of chained cast calls can lead to unexpected behaviour
> -------------------------------------------------------------------
>
> Key: CALCITE-4861
> URL: https://issues.apache.org/jira/browse/CALCITE-4861
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Marios Trivyzas
> Priority: Minor
>
> Simplification of Cast chained calls can lead to unexpected behaviour:
> CAST(CAST(CAST(123456 AS TINYINT) AS INT) AS BIGINT)
> is simplified to
> {noformat}
> CAST(123456 AS BIGINT){noformat}
> and returns *123456* with *BIGINT* data type, where the first inner cast as
> TINYINT should already fail because the value is out of range.
> For example, for PostgreSQL:
> {noformat}
> postgres=# select 123456::smallint::int::bigint;
> ERROR: smallint out of range{noformat}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)