From dd2cbf4b497da69c1f61d4fd003fdf96e12c624c Mon Sep 17 00:00:00 2001 From: wangfeihuo Date: Sat, 15 Mar 2025 10:16:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=BD=AC=E6=8D=A2=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\345\207\275\346\225\260.md" | 49 +++++++++ ...54\346\215\242\345\207\275\346\225\260.md" | 102 +++++++++++++---- .../\345\207\275\346\225\260.md" | 54 ++++++++- ...54\346\215\242\345\207\275\346\225\260.md" | 103 +++++++++++++----- 4 files changed, 255 insertions(+), 53 deletions(-) diff --git "a/content/docs-lite/zh/docs/BriefTutorial/\345\207\275\346\225\260.md" "b/content/docs-lite/zh/docs/BriefTutorial/\345\207\275\346\225\260.md" index 9c09bf5c0..6f368e043 100644 --- "a/content/docs-lite/zh/docs/BriefTutorial/\345\207\275\346\225\260.md" +++ "b/content/docs-lite/zh/docs/BriefTutorial/\345\207\275\346\225\260.md" @@ -1102,6 +1102,9 @@ openGauss常用的函数如下: - to\_number\(text, text\) 描述:将字符串类型的值转换为指定格式的数字。 + * 在behavior_compat_options的correct_to_number开关关闭的时候,如有分组,expr分组的个数要求和fmt的分组个数一样,否则报错。 + + * 当fmt的模式配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理。 返回值类型:numeric @@ -1114,11 +1117,43 @@ openGauss常用的函数如下: -12454.8 (1 row) ``` + ``` + -- behavior_compat_options的correct_to_number开关关闭时不允许分组的数量不一样 + openGauss=# select to_number('123.45' ,'999,999.999'); + ERROR: invalid data. + CONTEXT: referenced column: to_number + openGauss=# set behavior_compat_options = 'correct_to_number'; + SET + openGauss=# select to_number('123.45' ,'999,999.999'); + to_number + ----------- + 123.45 + (1 row) + ``` + ``` + -- 当fmt的模式配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理 + openGauss=# select to_number('123,123','999999999'); + to_number + ----------- + 123123 + (1 row) + openGauss=# select to_number('123.123','999999999'); + to_number + ----------- + 123123 + (1 row) + openGauss=# select to_number('123S123','999999999'); + to_number + ----------- + 123123 + (1 row) + ``` - to\_timestamp\(text, text\) 描述:将字符串类型的值转换为指定格式的时间戳。 + * HH和HH12均为01-12小时格式,在fmt指定为HH和HH12的模式下且没明确指定pm的时间戳中,会将时间戳的第12小时按照第0小时处理。 返回值类型:timestamp @@ -1131,6 +1166,20 @@ openGauss常用的函数如下: 2000-12-05 00:00:00 (1 row) ``` + ``` + -- HH或者HH12的模式下,不指定为PM时间时12点按照0点处理 + openGauss=# select to_timestamp('2025-09-01 12:24:02','YYYY-MM-DD HH:MI:SS'); + to_timestamp + --------------------- + 2025-09-01 00:24:02 + (1 row) + + openGauss=# select to_timestamp('2025-09-01 12:24:02 pm','YYYY-MM-DD HH:MI:SS pm'); + to_timestamp + --------------------- + 2025-09-01 12:24:02 + (1 row) + ``` - to\_timestamp\(double precision\) diff --git "a/content/docs-lite/zh/docs/SQLReference/\347\261\273\345\236\213\350\275\254\346\215\242\345\207\275\346\225\260.md" "b/content/docs-lite/zh/docs/SQLReference/\347\261\273\345\236\213\350\275\254\346\215\242\345\207\275\346\225\260.md" index 68499834b..775b60ed8 100644 --- "a/content/docs-lite/zh/docs/SQLReference/\347\261\273\345\236\213\350\275\254\346\215\242\345\207\275\346\225\260.md" +++ "b/content/docs-lite/zh/docs/SQLReference/\347\261\273\345\236\213\350\275\254\346\215\242\345\207\275\346\225\260.md" @@ -403,11 +403,15 @@ 描述:将expr按指定格式转换为一个NUMBER类型的值。 - 类型转换格式请参考[表 2](#表-2-数值格式化的模版模式)。 + * 类型转换格式请参考[表 2](#表-2-数值格式化的模版模式)。 - 转换十六进制字符串为十进制数字时,最多支持16个字节的十六进制字符串转换为无符号数。 + * 转换十六进制字符串为十进制数字时,最多支持16个字节的十六进制字符串转换为无符号数。 - 转换十六进制字符串为十进制数字时,格式字符串中不允许出现除'x'或'X'以外的其他字符,否则报错。 + * 转换十六进制字符串为十进制数字时,格式字符串中不允许出现除'x'或'X'以外的其他字符,否则报错。 + + * 在behavior_compat_options的correct_to_number开关关闭时,如有分组,expr分组的个数要求和fmt的分组个数一样,否则报错。 + + * 当fmt的模板配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理。 返回值类型:number @@ -421,6 +425,39 @@ (1 row) ``` + ``` + -- behavior_compat_options的correct_to_number开关关闭时不允许分组的数量不一样 + openGauss=# select to_number('123.45' ,'999,999.999'); + ERROR: invalid data. + CONTEXT: referenced column: to_number + openGauss=# set behavior_compat_options = 'correct_to_number'; + SET + openGauss=# select to_number('123.45' ,'999,999.999'); + to_number + ----------- + 123.45 + (1 row) + ``` + + ``` + -- 当fmt的模板配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理 + openGauss=# select to_number('123,123','999999999'); + to_number + ----------- + 123123 + (1 row) + openGauss=# select to_number('123.123','999999999'); + to_number + ----------- + 123123 + (1 row) + openGauss=# select to_number('123S123','999999999'); + to_number + ----------- + 123123 + (1 row) + ``` + - to\_number\(text, text\) 描述:将字符串类型的值转换为指定格式的数字。 @@ -459,8 +496,10 @@ openGauss的to\_timestamp中, + - 类型转换格式请参考[表 1](#表-1-日期格式化的模板模式)。 - 如果输入的年份YYYY=0,系统报错。 - 如果输入的年份YYYY<0,在fmt中指定SYYYY,则正确输出公元前绝对值n的年份。 + - HH和HH12均为01-12小时格式,在fmt指定为HH和HH12的模式下且没明确指定pm的时间戳中,会将时间戳的第12小时按照第0小时处理。 fmt中出现的字符必须与日期/时间格式化的模式相匹配,否则报错。 @@ -514,6 +553,21 @@ (1 row) ``` + ``` + -- HH或者HH12的模式下,不指定为PM时间时12点按照0点处理 + openGauss=# select to_timestamp('2025-09-01 12:24:02','YYYY-MM-DD HH:MI:SS'); + to_timestamp + --------------------- + 2025-09-01 00:24:02 + (1 row) + + openGauss=# select to_timestamp('2025-09-01 12:24:02 pm','YYYY-MM-DD HH:MI:SS pm'); + to_timestamp + --------------------- + 2025-09-01 12:24:02 + (1 row) + ``` + - to\_timestamp\(text, text\) 描述:将字符串类型的值转换为指定格式的时间戳。 @@ -1355,27 +1409,27 @@ ### 表 1 日期格式化的模板模式 -| 模式 | 描述 | -| ------------------------------ | -------------------------- | -| `HH` | 小时(01-12) | -| `HH12` | 小时(01-12) | -| `HH24` | 小时(01-24) | -| `MI` | 分钟(00-59) | -| `SS` | 秒(00-59) | -| `MS` | 毫秒(000-999) | -| `US` | 微秒(000000-999999) | -| `Y,YYY` | 带逗号的年份(4 位或以上) | -| `YYYY` | 年份(4 位或以上) | -| `BC`,`bc`,`AD`,`ad` | 指示年代 | -| `B.C.`,`b.c.`,`A.D.`,`a.d.` | 指示年代 | -| `MONTH` | 大写月份名 | -| `Month` | 驼峰月份名 | -| `month` | 小写月份名 | -| `MON` | 大写月份缩写 | -| `Mon` | 驼峰月份缩写 | -| `mon` | 小写月份缩写 | -| `MM` | 月份(01-12) | -| `DD` | 日期(01-31) | +| 模式 | 描述 | +| ------------------------------ | ---------------------------------------------- | +| `HH` | 小时(01-12),不指定为PM时间时12点按照0点处理 | +| `HH12` | 小时(01-12),不指定为PM时间时12点按照0点处理 | +| `HH24` | 小时(01-24) | +| `MI` | 分钟(00-59) | +| `SS` | 秒(00-59) | +| `MS` | 毫秒(000-999) | +| `US` | 微秒(000000-999999) | +| `Y,YYY` | 带逗号的年份(4 位或以上) | +| `YYYY` | 年份(4 位或以上) | +| `BC`,`bc`,`AD`,`ad` | 指示年代 | +| `B.C.`,`b.c.`,`A.D.`,`a.d.` | 指示年代 | +| `MONTH` | 大写月份名 | +| `Month` | 驼峰月份名 | +| `month` | 小写月份名 | +| `MON` | 大写月份缩写 | +| `Mon` | 驼峰月份缩写 | +| `mon` | 小写月份缩写 | +| `MM` | 月份(01-12) | +| `DD` | 日期(01-31) | ### 表 2 数值格式化的模版模式 diff --git "a/content/zh/docs/BriefTutorial/\345\207\275\346\225\260.md" "b/content/zh/docs/BriefTutorial/\345\207\275\346\225\260.md" index 039559b1d..1fa5b8911 100644 --- "a/content/zh/docs/BriefTutorial/\345\207\275\346\225\260.md" +++ "b/content/zh/docs/BriefTutorial/\345\207\275\346\225\260.md" @@ -1103,6 +1103,10 @@ openGauss常用的函数如下: 描述:将字符串类型的值转换为指定格式的数字。 + * 在behavior_compat_options的correct_to_number开关关闭的时候,如有分组,expr分组的个数要求和fmt的分组个数一样,否则报错。 + + * 当fmt的模式配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理。 + 返回值类型:numeric 示例: @@ -1115,11 +1119,45 @@ openGauss常用的函数如下: (1 row) ``` + ``` + -- behavior_compat_options的correct_to_number开关关闭时不允许分组的数量不一样 + openGauss=# select to_number('123.45' ,'999,999.999'); + ERROR: invalid data. + CONTEXT: referenced column: to_number + openGauss=# set behavior_compat_options = 'correct_to_number'; + SET + openGauss=# select to_number('123.45' ,'999,999.999'); + to_number + ----------- + 123.45 + (1 row) + ``` + + ``` + -- 当fmt的模式配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理 + openGauss=# select to_number('123,123','999999999'); + to_number + ----------- + 123123 + (1 row) + openGauss=# select to_number('123.123','999999999'); + to_number + ----------- + 123123 + (1 row) + openGauss=# select to_number('123S123','999999999'); + to_number + ----------- + 123123 + (1 row) + ``` - to\_timestamp\(text, text\) 描述:将字符串类型的值转换为指定格式的时间戳。 + * HH和HH12均为01-12小时格式,在fmt指定为HH和HH12的模式下且没明确指定pm的时间戳中,会将时间戳的第12小时按照第0小时处理。 + 返回值类型:timestamp 示例: @@ -1131,7 +1169,21 @@ openGauss常用的函数如下: 2000-12-05 00:00:00 (1 row) ``` - + + ``` + -- HH或者HH12的模式下,不指定为PM时间时12点按照0点处理 + openGauss=# select to_timestamp('2025-09-01 12:24:02','YYYY-MM-DD HH:MI:SS'); + to_timestamp + --------------------- + 2025-09-01 00:24:02 + (1 row) + + openGauss=# select to_timestamp('2025-09-01 12:24:02 pm','YYYY-MM-DD HH:MI:SS pm'); + to_timestamp + --------------------- + 2025-09-01 12:24:02 + (1 row) + ``` - to\_timestamp\(double precision\) diff --git "a/content/zh/docs/SQLReference/\347\261\273\345\236\213\350\275\254\346\215\242\345\207\275\346\225\260.md" "b/content/zh/docs/SQLReference/\347\261\273\345\236\213\350\275\254\346\215\242\345\207\275\346\225\260.md" index 62a7249c5..840c4fed9 100644 --- "a/content/zh/docs/SQLReference/\347\261\273\345\236\213\350\275\254\346\215\242\345\207\275\346\225\260.md" +++ "b/content/zh/docs/SQLReference/\347\261\273\345\236\213\350\275\254\346\215\242\345\207\275\346\225\260.md" @@ -404,13 +404,13 @@ 描述:将expr按指定格式转换为一个NUMBER类型的值。 - 类型转换格式请参考[表 2](#表-2-数值格式化的模版模式)。 + * 类型转换格式请参考[表 2](#表-2-数值格式化的模版模式)。 - 转换十六进制字符串为十进制数字时,最多支持16个字节的十六进制字符串转换为无符号数。 + * 转换十六进制字符串为十进制数字时,最多支持16个字节的十六进制字符串转换为无符号数。 - 转换十六进制字符串为十进制数字时,格式字符串中不允许出现除'x'或'X'以外的其他字符,否则报错。 - - 返回值类型:number + * 转换十六进制字符串为十进制数字时,格式字符串中不允许出现除'x'或'X'以外的其他字符,否则报错。 + * 在behavior_compat_options的correct_to_number开关关闭的时候,如有分组,expr分组的个数要求和fmt的分组个数一样,否则报错。 + * 当fmt的模式配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理。 示例: @@ -421,6 +421,38 @@ -12454.8 (1 row) ``` + ``` + -- behavior_compat_options的correct_to_number开关关闭时不允许分组的数量不一样 + openGauss=# select to_number('123.45' ,'999,999.999'); + ERROR: invalid data. + CONTEXT: referenced column: to_number + openGauss=# set behavior_compat_options = 'correct_to_number'; + SET + openGauss=# select to_number('123.45' ,'999,999.999'); + to_number + ----------- + 123.45 + (1 row) + ``` + + ``` + -- 当fmt的模式配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理 + openGauss=# select to_number('123,123','999999999'); + to_number + ----------- + 123123 + (1 row) + openGauss=# select to_number('123.123','999999999'); + to_number + ----------- + 123123 + (1 row) + openGauss=# select to_number('123S123','999999999'); + to_number + ----------- + 123123 + (1 row) + ``` - to\_number\(text, text\) @@ -462,8 +494,8 @@ - 如果输入的年份YYYY=0,系统报错。 - 如果输入的年份YYYY<0,在fmt中指定SYYYY,则正确输出公元前绝对值n的年份。 - - fmt中出现的字符必须与日期/时间格式化的模式相匹配,否则报错。 + - fmt中出现的字符必须与日期/时间格式化的模式相匹配,否则报错。 + - HH和HH12均为01-12小时格式,在fmt指定为HH和HH12的模式下且没明确指定pm的时间戳中,会将时间戳的第12小时按照第0小时处理。 返回值类型:timestamp without time zone @@ -515,6 +547,21 @@ (1 row) ``` + ``` + -- HH或者HH12的模式下,不指定为PM时间时12点按照0点处理 + openGauss=# select to_timestamp('2025-09-01 12:24:02','YYYY-MM-DD HH:MI:SS'); + to_timestamp + --------------------- + 2025-09-01 00:24:02 + (1 row) + + openGauss=# select to_timestamp('2025-09-01 12:24:02 pm','YYYY-MM-DD HH:MI:SS pm'); + to_timestamp + --------------------- + 2025-09-01 12:24:02 + (1 row) + ``` + - to\_timestamp\(text, text\) 描述:将字符串类型的值转换为指定格式的时间戳。 @@ -1358,27 +1405,27 @@ ### 表 1 日期格式化的模板模式 -| 模式 | 描述 | -| ------------------------------ | -------------------------- | -| `HH` | 小时(01-12) | -| `HH12` | 小时(01-12) | -| `HH24` | 小时(01-24) | -| `MI` | 分钟(00-59) | -| `SS` | 秒(00-59) | -| `MS` | 毫秒(000-999) | -| `US` | 微秒(000000-999999) | -| `Y,YYY` | 带逗号的年份(4 位或以上) | -| `YYYY` | 年份(4 位或以上) | -| `BC`,`bc`,`AD`,`ad` | 指示年代 | -| `B.C.`,`b.c.`,`A.D.`,`a.d.` | 指示年代 | -| `MONTH` | 大写月份名 | -| `Month` | 驼峰月份名 | -| `month` | 小写月份名 | -| `MON` | 大写月份缩写 | -| `Mon` | 驼峰月份缩写 | -| `mon` | 小写月份缩写 | -| `MM` | 月份(01-12) | -| `DD` | 日期(01-31) | +| 模式 | 描述 | +| ------------------------------ | ---------------------------------------------- | +| `HH` | 小时(01-12),不指定为PM时间时12点按照0点处理 | +| `HH12` | 小时(01-12),不指定为PM时间时12点按照0点处理 | +| `HH24` | 小时(01-24) | +| `MI` | 分钟(00-59) | +| `SS` | 秒(00-59) | +| `MS` | 毫秒(000-999) | +| `US` | 微秒(000000-999999) | +| `Y,YYY` | 带逗号的年份(4 位或以上) | +| `YYYY` | 年份(4 位或以上) | +| `BC`,`bc`,`AD`,`ad` | 指示年代 | +| `B.C.`,`b.c.`,`A.D.`,`a.d.` | 指示年代 | +| `MONTH` | 大写月份名 | +| `Month` | 驼峰月份名 | +| `month` | 小写月份名 | +| `MON` | 大写月份缩写 | +| `Mon` | 驼峰月份缩写 | +| `mon` | 小写月份缩写 | +| `MM` | 月份(01-12) | +| `DD` | 日期(01-31) | ### 表 2 数值格式化的模版模式 -- Gitee