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 4aa1ccf68263c26851708cd4dcf0c3a63bacfb94..a9d5d887ce42af1687591782abd675ba421ec9e4 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" @@ -1157,7 +1157,10 @@ openGauss常用的函数如下: * 转换十六进制字符串为十进制数字时,最多支持16个字节的十六进制字符串转换为无符号数。 * 转换十六进制字符串为十进制数字时,格式字符串中不允许出现除'x'或'X'以外的其他字符,否则报错。 - + + * 在behavior_compat_options的correct_to_number开关关闭的时候,如有分组,expr分组的个数要求和fmt的分组个数一样,否则报错。 + + * 当fmt的模式配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理。 返回值类型:numeric @@ -1204,7 +1207,38 @@ openGauss常用的函数如下: 321456231 (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\(double precision\) @@ -1229,6 +1263,7 @@ openGauss常用的函数如下: * 如果输入的年份YYYY<0,在fmt中指定SYYYY,则正确输出公元前绝对值n的年 份。 * fmt中的类似于MM的参数,不可大小写混用。 * fmt和string时间信息中的连接符可以替换为其他符号。例:SELECT to_timestamp('05*Dec^2000', 'DD Mon+YYYY'); + * HH和HH12均为01-12小时格式,在fmt指定为HH和HH12的模式下且没明确指定pm的时间戳中,会将时间戳的第12小时按照第0小时处理。 返回值类型:timestamp without time zone @@ -1297,5 +1332,17 @@ 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) + ``` 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 3462c8614bff081f2f6e860501d2ab7a09de7a95..eb3c2c39ca3b84b907d3a79825e0328d51e18a37 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" @@ -512,6 +512,10 @@ * 转换十六进制字符串为十进制数字时,格式字符串中不允许出现除'x'或'X'以外的其他字符,否则报错。 + * 在behavior_compat_options的correct_to_number开关关闭时,如有分组,expr分组的个数要求和fmt的分组个数一样,否则报错。 + + * 当fmt的模板配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理。 + 返回值类型:numeric @@ -558,6 +562,39 @@ 321456231 (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\(double precision\) @@ -581,8 +618,10 @@ openGauss的to\_timestamp中, + - 类型转换格式请参考[表 1](#表-1-日期格式化的模板模式)。 - 如果输入的年份YYYY=0,系统报错。 - 如果输入的年份YYYY<0,在fmt中指定SYYYY,则正确输出公元前绝对值n的年份。 + - HH和HH12均为01-12小时格式,在fmt指定为HH和HH12的模式下且没明确指定pm的时间戳中,会将时间戳的第12小时按照第0小时处理。 fmt中出现的字符必须与日期/时间格式化的模式相匹配,否则报错。 @@ -636,6 +675,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\) 描述:将字符串类型的值转换为指定格式的时间戳。 @@ -1477,27 +1531,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 7c03d565359f86d02e0a12c1944c9b1d0adb5c95..f17f045fea405820b2ede0b01d1e4579b3156921 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" @@ -1157,6 +1157,9 @@ openGauss常用的函数如下: * 转换十六进制字符串为十进制数字时,格式字符串中不允许出现除'x'或'X'以外的其他字符,否则报错。 + * 在behavior_compat_options的correct_to_number开关关闭的时候,如有分组,expr分组的个数要求和fmt的分组个数一样,否则报错。 + + * 当fmt的模式配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理。 返回值类型:numeric @@ -1204,6 +1207,39 @@ 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\(double precision\) @@ -1229,11 +1265,12 @@ openGauss常用的函数如下: * 如果输入的年份YYYY<0,在fmt中指定SYYYY,则正确输出公元前绝对值n的年份。 * fmt中的类似于MM的参数,不可大小写混用。 * fmt和string时间信息中的连接符可以替换为其他符号。例:SELECT to_timestamp('05*Dec^2000', 'DD Mon+YYYY'); - + * HH和HH12均为01-12小时格式,在fmt指定为HH和HH12的模式下且没明确指定pm的时间戳中,会将时间戳的第12小时按照第0小时处理。 + 返回值类型:timestamp without time zone - + 示例: - + ``` openGauss=# SHOW nls_timestamp_format; nls_timestamp_format @@ -1297,4 +1334,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) + ``` + + 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 03864edadf352572a0fdda87514a2cdafa6822a7..bb717a72e6b561cb379977ddca2aa7d395a21458 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" @@ -552,7 +552,8 @@ * 转换十六进制字符串为十进制数字时,最多支持16个字节的十六进制字符串转换为无符号数。 * 转换十六进制字符串为十进制数字时,格式字符串中不允许出现除'x'或'X'以外的其他字符,否则报错。 - + * 在behavior_compat_options的correct_to_number开关关闭的时候,如有分组,expr分组的个数要求和fmt的分组个数一样,否则报错。 + * 当fmt的模式配置为数值位(模式为9)时,对于expr 中的非数值输入会进行忽略处理。 返回值类型:numeric @@ -599,6 +600,39 @@ 321456231 (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\(double precision\) @@ -619,10 +653,12 @@ - to\_timestamp(string \[ DEFAULT return_value ON CONVERSION ERROR ] \[ , fmt [, 'nlsparam' ] ]\) 描述:将字符串转换为时间戳。默认的输入格式为[DD-Mon-YYYY HH12:MI:SS.FF],是12小时制的AM。若输入值string不为默认的格式,则需要用户在fmt处描述自己的输入格式,若格式描述错误则报错。若string部分转换失败,则会尝试转换关键字DEFAULT后的return_value(return_value的输入格式受fmt约束)。若Mon处为Jan这样的英文缩写,则可以在nlsparam处设置月份的描述语言(目前仅支持American和English)。 + * 类型转换格式请参考[表 1](#表-1-日期格式化的模板模式)。 * 如果输入的年份YYYY=0,系统报错。 * 如果输入的年份YYYY<0,在fmt中指定SYYYY,则正确输出公元前绝对值n的年份。 * fmt中的类似于MM的参数,不可大小写混用。 * fmt和string时间信息中的连接符可以替换为其他符号。例:SELECT to_timestamp('05*Dec^2000', 'DD Mon+YYYY'); + * HH和HH12均为01-12小时格式,在fmt指定为HH和HH12的模式下且没明确指定pm的时间戳中,会将时间戳的第12小时按照第0小时处理。 返回值类型:timestamp without time zone @@ -691,7 +727,20 @@ 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) + ``` - abstime\_text @@ -1519,27 +1568,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 数值格式化的模版模式