user4601931
user4601931

Reputation: 5285

Odd conversion behavior in Amazon Redshift

Here is a minimal example of some bizarre behavior I'm seeing with Amazon Redshift. Both of these queries

select 0.010691::DECIMAL(20,4);
select ('0.010691'::varchar(255))::DECIMAL(20,4);

return 0.0107, which is what I would expect. But

create table test (
  "val" varchar(255)
);
insert into test values ('0.010691');
select val::DECIMAL(20, 4) from test;

returns 0.0106, i.e., it truncates before converting instead of converting, then rounding. Is this expected behavior? Why are these different?

Upvotes: 0

Views: 48

Answers (1)

user4601931
user4601931

Reputation: 5285

Apparently, it is expected behavior. In this documentation page, there is the line, "However, results of explicit casts of values selected from tables are not rounded." So, a feature, not a bug.

Upvotes: 1

Related Questions