enable_numeric_rounding - Amazon Redshift
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

enable_numeric_rounding

值(默认为粗体)

on(true),off(false)

描述

指定是否使用数值四舍五入。如果 enable_numeric_roundingon,则 Amazon Redshift 在将 NUMERIC 值强制转换为其他数值类型(例如 INTEGER 或 DECIMAL)时会四舍五入。如果 enable_numeric_roundingoff,则 Amazon Redshift 会在将 NUMERIC 值强制转换为其他数值类型时将其截断。有关数值类型的更多信息,请参阅数字类型

示例

--Create a table and insert the numeric value 1.5 into it. CREATE TABLE t (a numeric(10, 2)); INSERT INTO t VALUES (1.5); SET enable_numeric_rounding to ON; --Amazon Redshift now rounds NUMERIC values when casting to other numeric types. SELECT a::int FROM t; a --- 2 (1 row) SELECT a::decimal(10, 0) FROM t; a --- 2 (1 row) SELECT a::decimal(10, 5) FROM t; a --------- 1.50000 (1 row) SET enable_numeric_rounding to OFF; --Amazon Redshift now truncates NUMERIC values when casting to other numeric types. SELECT a::int FROM t; a --- 1 (1 row) SELECT a::decimal(10, 0) FROM t; a --- 1 (1 row) SELECT a::decimal(10, 5) FROM t; a --------- 1.50000 (1 row)