diff --git a/src/common/backend/utils/misc/guc/guc_sql.cpp b/src/common/backend/utils/misc/guc/guc_sql.cpp index eeb0c890f..c93ebfd88 100755 --- a/src/common/backend/utils/misc/guc/guc_sql.cpp +++ b/src/common/backend/utils/misc/guc/guc_sql.cpp @@ -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) diff --git a/src/test/regress/expected/numeric_hide_tailing_zero.out b/src/test/regress/expected/numeric_hide_tailing_zero.out index 2b619fad3..80c3cc14c 100644 --- a/src/test/regress/expected/numeric_hide_tailing_zero.out +++ b/src/test/regress/expected/numeric_hide_tailing_zero.out @@ -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); diff --git a/src/test/regress/sql/numeric_hide_tailing_zero.sql b/src/test/regress/sql/numeric_hide_tailing_zero.sql index 63c16e5ec..b52e5d345 100644 --- a/src/test/regress/sql/numeric_hide_tailing_zero.sql +++ b/src/test/regress/sql/numeric_hide_tailing_zero.sql @@ -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);