!6099 新增nls_initcap函数

Merge pull request !6099 from Rock/nls_initcap
This commit is contained in:
opengauss_bot
2024-11-06 08:42:41 +00:00
committed by Gitee
10 changed files with 124 additions and 3 deletions

View File

@ -7377,6 +7377,10 @@
"nlssort", 1,
AddBuiltinFunc(_0(1849), _1("nlssort"), _2(2), _3(false), _4(false), _5(nlssort), _6(25), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('i'), _19(0), _20(2, 25, 25), _21(NULL), _22(NULL), _23(NULL), _24(NULL), _25("nlssort"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(true), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))
),
AddFuncGroup(
"nls_initcap", 1,
AddBuiltinFunc(_0(9537), _1("nls_initcap"), _2(2), _3(false), _4(false), _5(nls_initcap), _6(25), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('i'), _19(1), _20(2, 25, 25), _21(NULL), _22(2,'i','i'), _23(2,"str","nlsparam"), _24("({CONST :consttype 25 :consttypmod -1 :constcollid 100 :constlen -1 :constbyval false :constisnull true :ismaxvalue false :location 68 :constvalue <> :cursor_data :row_count 0 :cur_dno -1 :is_open false :found false :not_found false :null_open false :null_fetch false})"), _25("nls_initcap"), _26(NULL), _27(NULL), _28(NULL), _29(1,1), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))
),
AddFuncGroup(
"node_oid_name", 1,
AddBuiltinFunc(_0(3950), _1("node_oid_name"), _2(1), _3(true), _4(false), _5(node_oid_name), _6(2275), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('i'), _19(0), _20(1, 26), _21(NULL), _22(NULL), _23(NULL), _24(NULL), _25("node_oid_name"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))
@ -13503,4 +13507,4 @@ AddFuncGroup(
AddFuncGroup(
"sparsevec_to_vector", 1,
AddBuiltinFunc(_0(8230), _1("sparsevec_to_vector"), _2(3), _3(true), _4(false), _5(sparsevec_to_vector), _6(8305), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(3, 8307, 23, 16), _21(NULL), _22(NULL), _23(NULL), _24(NULL), _25("sparsevec_to_vector"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33("NULL"), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))
),
),

View File

@ -112,6 +112,41 @@ Datum initcap(PG_FUNCTION_ARGS)
PG_RETURN_TEXT_P(result);
}
/********************************************************************
*
* nls_initcap
*
* Syntax:
*
* text nls_initcap(text string)
*
* Purpose:
*
* Returns string, with first letter of each word in uppercase, all
* other letters in lowercase. A word is defined as a sequence of
* alphanumeric characters, delimited by non-alphanumeric
* characters.
*
********************************************************************/
Datum nls_initcap(PG_FUNCTION_ARGS)
{
text* in_string = PG_GETARG_TEXT_PP(0);
if (!PG_ARGISNULL(1)) {
ereport(NOTICE,
(errcode(ERRCODE_OPERATE_INVALID_PARAM),
errmsg("The second parameter of this function will not take effect.")));
}
char* out_string = NULL;
text* result = NULL;
FUNC_CHECK_HUGE_POINTER(false, in_string, "nls_initcap()");
out_string = str_initcap(VARDATA_ANY(in_string), VARSIZE_ANY_EXHDR(in_string), PG_GET_COLLATION());
result = cstring_to_text(out_string);
pfree_ext(out_string);
PG_RETURN_TEXT_P(result);
}
/********************************************************************
*
* lpad

View File

@ -77,7 +77,7 @@ bool will_shutdown = false;
*
********************************************/
const uint32 GRAND_VERSION_NUM = 93020;
const uint32 GRAND_VERSION_NUM = 93021;
/********************************************
* 2.VERSION NUM FOR EACH FEATURE

View File

@ -0,0 +1 @@
DROP FUNCTION IF EXISTS pg_catalog.nls_initcap(text, text) CASCADE;

View File

@ -0,0 +1 @@
DROP FUNCTION IF EXISTS pg_catalog.nls_initcap(text, text) CASCADE;

View File

@ -0,0 +1,7 @@
DROP FUNCTION IF EXISTS pg_catalog.nls_initcap(text, text) CASCADE;
SET LOCAL inplace_upgrade_next_system_object_oids=IUO_PROC, 9537;
CREATE OR REPLACE FUNCTION pg_catalog.nls_initcap(str text, nlsparam text DEFAULT NULL::text)
RETURNS text
LANGUAGE internal
IMMUTABLE NOT FENCED NOT SHIPPABLE
AS $function$nls_initcap$function$;

View File

@ -0,0 +1,8 @@
DROP FUNCTION IF EXISTS pg_catalog.nls_initcap(text, text) CASCADE;
SET LOCAL inplace_upgrade_next_system_object_oids=IUO_PROC, 9537;
CREATE OR REPLACE FUNCTION pg_catalog.nls_initcap(str text, nlsparam text DEFAULT NULL::text)
RETURNS text
LANGUAGE internal
IMMUTABLE NOT FENCED NOT SHIPPABLE
AS $function$nls_initcap$function$;

View File

@ -1746,6 +1746,7 @@ extern Datum pg_lsn_in(PG_FUNCTION_ARGS);
/* nlssort.cpp */
extern Datum nlssort(PG_FUNCTION_ARGS);
extern Datum nls_initcap(PG_FUNCTION_ARGS);
extern char *remove_trailing_spaces(const char *src_str);
// template function implementation

View File

@ -2,6 +2,62 @@ create database pl_test_funcion DBCOMPATIBILITY 'pg';
\c pl_test_funcion;
create schema distribute_function;
set current_schema = distribute_function;
select nls_initcap('hello word');
nls_initcap
-------------
Hello Word
(1 row)
select nls_initcap('журнал журнал');--俄语
nls_initcap
---------------
Журнал Журнал
(1 row)
SELECT nls_initcap('el gato negro');--西班牙语
nls_initcap
---------------
El Gato Negro
(1 row)
SELECT nls_initcap('o gato preto');--葡萄牙语
nls_initcap
--------------
O Gato Preto
(1 row)
SELECT nls_initcap('HELLO ß world', 'NLS_SORT = XGERMAN'); --第二个参数不支持。
NOTICE: The second parameter of this function will not take effect.
CONTEXT: referenced column: nls_initcap
nls_initcap
---------------
Hello ß World
(1 row)
select nls_initcap('hello word'); --3个空格
nls_initcap
--------------
Hello Word
(1 row)
select nls_initcap('hello word'); --2个tab键等作为分隔符
nls_initcap
-------------------
Hello Word
(1 row)
select nls_initcap('hello *** &&& ()()() 你好啦 word'); --中间有其他非英文字母,或者中文等
nls_initcap
----------------------------------------
Hello *** &&& ()()() 你好啦 Word
(1 row)
SELECT nls_initcap('o gato preto','o gato preto','o gato preto');--报错
ERROR: function nls_initcap(unknown, unknown, unknown) does not exist
LINE 1: SELECT nls_initcap('o gato preto','o gato preto','o gato pre...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
CONTEXT: referenced column: nls_initcap
create table function_table_01(f1 int, f2 float, f3 text);
insert into function_table_01 values(1,2.0,'abcde'),(2,4.0,'abcde'),(3,5.0,'affde');
insert into function_table_01 values(4,7.0,'aeede'),(5,1.0,'facde'),(6,3.0,'affde');

View File

@ -2,7 +2,15 @@ create database pl_test_funcion DBCOMPATIBILITY 'pg';
\c pl_test_funcion;
create schema distribute_function;
set current_schema = distribute_function;
select nls_initcap('hello word');
select nls_initcap('журнал журнал');--
SELECT nls_initcap('el gato negro');--西
SELECT nls_initcap('o gato preto');--
SELECT nls_initcap('HELLO ß world', 'NLS_SORT = XGERMAN'); --
select nls_initcap('hello word'); --3
select nls_initcap('hello word'); --2tab键等作为分隔符
select nls_initcap('hello *** &&& ()()() 你好啦 word'); --
SELECT nls_initcap('o gato preto','o gato preto','o gato preto');--
create table function_table_01(f1 int, f2 float, f3 text);
insert into function_table_01 values(1,2.0,'abcde'),(2,4.0,'abcde'),(3,5.0,'affde');
insert into function_table_01 values(4,7.0,'aeede'),(5,1.0,'facde'),(6,3.0,'affde');