This is an automated email from the ASF dual-hosted git repository.
luzhijing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push:
new 49a1660dd5b7 [doc] function truncate update (#516)
49a1660dd5b7 is described below
commit 49a1660dd5b7134597d47f967e9928847a6b3c70
Author: zhiqiang <[email protected]>
AuthorDate: Mon Apr 8 12:27:59 2024 +0800
[doc] function truncate update (#516)
---
.../sql-functions/numeric-functions/truncate.md | 27 +++++++++++++++++-----
.../sql-functions/numeric-functions/truncate.md | 27 +++++++++++++++++-----
.../sql-functions/numeric-functions/truncate.md | 27 +++++++++++++++++-----
.../sql-functions/numeric-functions/truncate.md | 27 +++++++++++++++++-----
4 files changed, 84 insertions(+), 24 deletions(-)
diff --git a/docs/sql-manual/sql-functions/numeric-functions/truncate.md
b/docs/sql-manual/sql-functions/numeric-functions/truncate.md
index ca0e3ccc4a46..79e8de2886ad 100644
--- a/docs/sql-manual/sql-functions/numeric-functions/truncate.md
+++ b/docs/sql-manual/sql-functions/numeric-functions/truncate.md
@@ -26,14 +26,18 @@ under the License.
### description
#### Syntax
+`DOUBLE truncate(DOUBLE x, INT d)`
-`DOUBLE truncate(DOUBLE x, INT d)`
-Numerically truncate `x` according to the number of decimal places `d`.
+Numerically truncate `x` according to the number of decimal places `d`.
-The rules are as follows:
-When `d > 0`: keep `d` decimal places of `x`
-When `d = 0`: remove the fractional part of `x` and keep only the integer part
-When `d < 0`: Remove the fractional part of `x`, and replace the integer part
with the number `0` according to the number of digits specified by `d`
+The rules are as follows:
+
+If `d` is literal:
+When `d > 0`: keep `d` decimal places of `x`
+When `d = 0`: remove the fractional part of `x` and keep only the integer part
+When `d < 0`: Remove the fractional part of `x`, and replace the integer part
with the number `0` according to the number of digits specified by `d`
+
+Else if `d` is a column, and `x` has Decimal type, scale of result Decimal
will always be same with input Decimal.
### example
@@ -56,6 +60,17 @@ mysql> select truncate(-124.3867, -2);
+-------------------------+
| -100 |
+-------------------------+
+mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast
("123.123456" as Decimal(9,6)), number) from numbers("number"="5");
+--------------
++---------------------------------------+--------+----------------------------------------------------------------------+
+| cast('123.123456' as DECIMALV3(9, 6)) | number | truncate(cast('123.123456'
as DECIMALV3(9, 6)), cast(number as INT)) |
++---------------------------------------+--------+----------------------------------------------------------------------+
+| 123.123456 | 0 |
123.000000 |
+| 123.123456 | 1 |
123.100000 |
+| 123.123456 | 2 |
123.120000 |
+| 123.123456 | 3 |
123.123000 |
+| 123.123456 | 4 |
123.123400 |
++---------------------------------------+--------+----------------------------------------------------------------------+
```
### keywords
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/numeric-functions/truncate.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/numeric-functions/truncate.md
index e13d291772fb..41e656fc55c2 100644
---
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/numeric-functions/truncate.md
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/numeric-functions/truncate.md
@@ -27,13 +27,17 @@ under the License.
### description
#### Syntax
-`DOUBLE truncate(DOUBLE x, INT d)`
-按照保留小数的位数`d`对`x`进行数值截取。
+`DOUBLE truncate(DOUBLE x, INT d)`
+按照保留小数的位数`d`对`x`进行数值截取。
-规则如下:
-当`d > 0`时:保留`x`的`d`位小数
-当`d = 0`时:将`x`的小数部分去除,只保留整数部分
-当`d < 0`时:将`x`的小数部分去除,整数部分按照 `d`所指定的位数,采用数字`0`进行替换
+规则如下:
+
+如果 `d` 为字面量:
+当`d > 0`时:保留`x`的`d`位小数
+当`d = 0`时:将`x`的小数部分去除,只保留整数部分
+当`d < 0`时:将`x`的小数部分去除,整数部分按照 `d`所指定的位数,采用数字`0`进行替换
+
+如果 `d` 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。
### example
@@ -56,6 +60,17 @@ mysql> select truncate(-124.3867, -2);
+-------------------------+
| -100 |
+-------------------------+
+mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast
("123.123456" as Decimal(9,6)), number) from numbers("number"="5");
+--------------
++---------------------------------------+--------+----------------------------------------------------------------------+
+| cast('123.123456' as DECIMALV3(9, 6)) | number | truncate(cast('123.123456'
as DECIMALV3(9, 6)), cast(number as INT)) |
++---------------------------------------+--------+----------------------------------------------------------------------+
+| 123.123456 | 0 |
123.000000 |
+| 123.123456 | 1 |
123.100000 |
+| 123.123456 | 2 |
123.120000 |
+| 123.123456 | 3 |
123.123000 |
+| 123.123456 | 4 |
123.123400 |
++---------------------------------------+--------+----------------------------------------------------------------------+
```
### keywords
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/numeric-functions/truncate.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/numeric-functions/truncate.md
index e13d291772fb..41e656fc55c2 100644
---
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/numeric-functions/truncate.md
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/numeric-functions/truncate.md
@@ -27,13 +27,17 @@ under the License.
### description
#### Syntax
-`DOUBLE truncate(DOUBLE x, INT d)`
-按照保留小数的位数`d`对`x`进行数值截取。
+`DOUBLE truncate(DOUBLE x, INT d)`
+按照保留小数的位数`d`对`x`进行数值截取。
-规则如下:
-当`d > 0`时:保留`x`的`d`位小数
-当`d = 0`时:将`x`的小数部分去除,只保留整数部分
-当`d < 0`时:将`x`的小数部分去除,整数部分按照 `d`所指定的位数,采用数字`0`进行替换
+规则如下:
+
+如果 `d` 为字面量:
+当`d > 0`时:保留`x`的`d`位小数
+当`d = 0`时:将`x`的小数部分去除,只保留整数部分
+当`d < 0`时:将`x`的小数部分去除,整数部分按照 `d`所指定的位数,采用数字`0`进行替换
+
+如果 `d` 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。
### example
@@ -56,6 +60,17 @@ mysql> select truncate(-124.3867, -2);
+-------------------------+
| -100 |
+-------------------------+
+mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast
("123.123456" as Decimal(9,6)), number) from numbers("number"="5");
+--------------
++---------------------------------------+--------+----------------------------------------------------------------------+
+| cast('123.123456' as DECIMALV3(9, 6)) | number | truncate(cast('123.123456'
as DECIMALV3(9, 6)), cast(number as INT)) |
++---------------------------------------+--------+----------------------------------------------------------------------+
+| 123.123456 | 0 |
123.000000 |
+| 123.123456 | 1 |
123.100000 |
+| 123.123456 | 2 |
123.120000 |
+| 123.123456 | 3 |
123.123000 |
+| 123.123456 | 4 |
123.123400 |
++---------------------------------------+--------+----------------------------------------------------------------------+
```
### keywords
diff --git
a/versioned_docs/version-2.1/sql-manual/sql-functions/numeric-functions/truncate.md
b/versioned_docs/version-2.1/sql-manual/sql-functions/numeric-functions/truncate.md
index ca0e3ccc4a46..79e8de2886ad 100644
---
a/versioned_docs/version-2.1/sql-manual/sql-functions/numeric-functions/truncate.md
+++
b/versioned_docs/version-2.1/sql-manual/sql-functions/numeric-functions/truncate.md
@@ -26,14 +26,18 @@ under the License.
### description
#### Syntax
+`DOUBLE truncate(DOUBLE x, INT d)`
-`DOUBLE truncate(DOUBLE x, INT d)`
-Numerically truncate `x` according to the number of decimal places `d`.
+Numerically truncate `x` according to the number of decimal places `d`.
-The rules are as follows:
-When `d > 0`: keep `d` decimal places of `x`
-When `d = 0`: remove the fractional part of `x` and keep only the integer part
-When `d < 0`: Remove the fractional part of `x`, and replace the integer part
with the number `0` according to the number of digits specified by `d`
+The rules are as follows:
+
+If `d` is literal:
+When `d > 0`: keep `d` decimal places of `x`
+When `d = 0`: remove the fractional part of `x` and keep only the integer part
+When `d < 0`: Remove the fractional part of `x`, and replace the integer part
with the number `0` according to the number of digits specified by `d`
+
+Else if `d` is a column, and `x` has Decimal type, scale of result Decimal
will always be same with input Decimal.
### example
@@ -56,6 +60,17 @@ mysql> select truncate(-124.3867, -2);
+-------------------------+
| -100 |
+-------------------------+
+mysql> select cast("123.123456" as Decimal(9,6)), number, truncate(cast
("123.123456" as Decimal(9,6)), number) from numbers("number"="5");
+--------------
++---------------------------------------+--------+----------------------------------------------------------------------+
+| cast('123.123456' as DECIMALV3(9, 6)) | number | truncate(cast('123.123456'
as DECIMALV3(9, 6)), cast(number as INT)) |
++---------------------------------------+--------+----------------------------------------------------------------------+
+| 123.123456 | 0 |
123.000000 |
+| 123.123456 | 1 |
123.100000 |
+| 123.123456 | 2 |
123.120000 |
+| 123.123456 | 3 |
123.123000 |
+| 123.123456 | 4 |
123.123400 |
++---------------------------------------+--------+----------------------------------------------------------------------+
```
### keywords
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]