修复show behavior_compat_options显示重复设置的参数

This commit is contained in:
梅程
2024-08-08 10:46:39 +08:00
parent d16b0aab69
commit 9299bbc799
3 changed files with 101 additions and 1 deletions

View File

@ -179,6 +179,7 @@ static bool check_b_format_behavior_compat_options(char **newval, void **extra,
static void assign_b_format_behavior_compat_options(const char *newval, void *extra);
static bool check_behavior_compat_options(char** newval, void** extra, GucSource source);
static void assign_behavior_compat_options(const char* newval, void* extra);
static const char* show_behavior_compat_options(void);
static bool check_plsql_compile_behavior_compat_options(char** newval, void** extra, GucSource source);
static void assign_plsql_compile_behavior_compat_options(const char* newval, void* extra);
static void assign_connection_info(const char* newval, void* extra);
@ -2919,7 +2920,7 @@ static void InitSqlConfigureNamesString()
"",
check_behavior_compat_options,
assign_behavior_compat_options,
NULL},
show_behavior_compat_options},
{{"disable_keyword_options",
PGC_USERSET,
NODE_ALL,
@ -3705,6 +3706,43 @@ static void assign_behavior_compat_options(const char* newval, void* extra)
u_sess->utils_cxt.behavior_compat_flags = result;
}
static const char* show_behavior_compat_options(void)
{
char *rawstring = NULL;
List *elemlist = NULL;
ListCell *cell = NULL;
int start = 0;
int64 result = 0;
StringInfoData strInfo;
bool isFirst = true;
initStringInfo(&strInfo);
rawstring = pstrdup(u_sess->attr.attr_sql.behavior_compat_string);
(void)SplitIdentifierString(rawstring, ',', &elemlist);
foreach (cell, elemlist) {
for (start = 0; start < OPT_MAX; start++) {
const char *item = (const char*)lfirst(cell);
if (strcmp(item, behavior_compat_options[start].name) == 0
&& (result & behavior_compat_options[start].flag) == 0) {
result += behavior_compat_options[start].flag;
if (isFirst) {
isFirst = false;
appendStringInfo(&strInfo, "%s", item);
} else {
appendStringInfo(&strInfo, ",%s", item);
}
}
}
}
pfree(rawstring);
list_free(elemlist);
return (const char *)strInfo.data;
}
typedef int16 (*getIgnoreKeywordTokenHook)(const char *item);
static int get_ignore_keyword_token(const char *item)

View File

@ -31,7 +31,58 @@ select cast(123.123 as numeric(15,10));
123.123
(1 row)
show behavior_compat_options;
behavior_compat_options
-------------------------
hide_tailing_zero
(1 row)
set behavior_compat_options='hide_tailing_zero,hide_tailing_zero,truncate_numeric_tail_zero,display_leading_zero';
show behavior_compat_options;
behavior_compat_options
-------------------------------------------------------------------
hide_tailing_zero,truncate_numeric_tail_zero,display_leading_zero
(1 row)
select cast(123.123 as numeric(15,10));
numeric
---------
123.123
(1 row)
set behavior_compat_options='hide_tailing_zero,truncate_numeric_tail_zero,display_leading_zero,display_leading_zero,correct_to_number';
show behavior_compat_options;
behavior_compat_options
-------------------------------------------------------------------------------------
hide_tailing_zero,truncate_numeric_tail_zero,display_leading_zero,correct_to_number
(1 row)
select cast(123.123 as numeric(15,10));
numeric
---------
123.123
(1 row)
set behavior_compat_options='truncate_numeric_tail_zero,truncate_numeric_tail_zero, hide_tailing_zero,hide_tailing_zero,hide_tailing_zero, truncate_numeric_tail_zero,hide_tailing_zero';
show behavior_compat_options;
behavior_compat_options
----------------------------------------------
truncate_numeric_tail_zero,hide_tailing_zero
(1 row)
select cast(123.123 as numeric(15,10));
numeric
---------
123.123
(1 row)
set behavior_compat_options='';
show behavior_compat_options;
behavior_compat_options
-------------------------
(1 row)
set behavior_compat_options='truncate_numeric_tail_zero';
create table test_num_zero (a number,b int);
insert into test_num_zero values(0.1000, 1);

View File

@ -6,7 +6,18 @@ select cast(0 as numeric(15,10));
select cast(009.0000 as numeric(15,10));
set behavior_compat_options='hide_tailing_zero,hide_tailing_zero';
select cast(123.123 as numeric(15,10));
show behavior_compat_options;
set behavior_compat_options='hide_tailing_zero,hide_tailing_zero,truncate_numeric_tail_zero,display_leading_zero';
show behavior_compat_options;
select cast(123.123 as numeric(15,10));
set behavior_compat_options='hide_tailing_zero,truncate_numeric_tail_zero,display_leading_zero,display_leading_zero,correct_to_number';
show behavior_compat_options;
select cast(123.123 as numeric(15,10));
set behavior_compat_options='truncate_numeric_tail_zero,truncate_numeric_tail_zero, hide_tailing_zero,hide_tailing_zero,hide_tailing_zero, truncate_numeric_tail_zero,hide_tailing_zero';
show behavior_compat_options;
select cast(123.123 as numeric(15,10));
set behavior_compat_options='';
show behavior_compat_options;
set behavior_compat_options='truncate_numeric_tail_zero';
create table test_num_zero (a number,b int);