!2459 修复set系统变量设置不支持类型变量转换导致的core问题

Merge pull request !2459 from suncan/master
This commit is contained in:
opengauss-bot
2022-11-21 08:47:23 +00:00
committed by Gitee
3 changed files with 58 additions and 10 deletions

View File

@ -2807,17 +2807,31 @@ Node *transferConstToAconst(Node *node)
const char *constr = value ? "t" : "f"; const char *constr = value ? "t" : "f";
val = makeString((char*)constr); val = makeString((char*)constr);
} break; } break;
case UNKNOWNOID: /*
* set configuration only support types above.
* if assigned value are not types above, will attempt to convert the type to text.
* if the type connot be converted to text also, an error is reported.
*/
default:
{
PG_TRY();
{ {
Const* con = (Const *)node; Const* con = (Const *)node;
Node* expr = coerce_type(NULL,(Node*)con , con->consttype, TEXTOID, -1, COERCION_IMPLICIT, COERCE_IMPLICIT_CAST, -1); Node* expr = coerce_type(NULL,(Node*)con , con->consttype, TEXTOID, -1, COERCION_IMPLICIT, COERCE_IMPLICIT_CAST, -1);
if (IsA(expr, Const) && (((Const*)expr)->consttype = TEXTOID)) {
char* constr = TextDatumGetCString(((Const*)expr)->constvalue); char* constr = TextDatumGetCString(((Const*)expr)->constvalue);
val = makeString(constr); val = makeString(constr);
} break; } else {
default: ereport(ERROR, (errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("set value cannot be assigned to the %s type", format_type_be(consttype))));
}
}
PG_CATCH();
{ {
char* constr = TextDatumGetCString(constval); ereport(ERROR, (errcode(ERRCODE_UNDEFINED_FUNCTION),
val = makeString(constr); errmsg("set value cannot be assigned to the %s type", format_type_be(consttype))));
}
PG_END_TRY();
} break; } break;
} }

View File

@ -19,6 +19,12 @@ set session codegen_cost_threshold = 10000 * 1;
set codegen_cost_threshold = 10000 * 1; set codegen_cost_threshold = 10000 * 1;
set codegen_cost_threshold = (select 10000); set codegen_cost_threshold = (select 10000);
-- test type not support
set codegen_cost_threshold = '1'::money;
set @@session.codegen_cost_threshold = '1'::money;
set application_name = '00:00:01'::time;
set @@session.application_name = '00:00:01'::time;
create database test_set dbcompatibility 'b'; create database test_set dbcompatibility 'b';
\c test_set \c test_set
-- dbcompatibility is B Format, enable_set_variable_b_format=off -- dbcompatibility is B Format, enable_set_variable_b_format=off
@ -243,6 +249,12 @@ set global log_destination = stderr,syslog , @v1:= 1, @@codegen_cost_threshold =
set global log_destination = stderr,syslog , @v1:= 1, @@codegen_cost_threshold = aa; set global log_destination = stderr,syslog , @v1:= 1, @@codegen_cost_threshold = aa;
set global log_destination = 'stderr', @v1:= 1, @@codegen_cost_threshold = 'aa'; set global log_destination = 'stderr', @v1:= 1, @@codegen_cost_threshold = 'aa';
-- test type not support
set codegen_cost_threshold = '1'::money;
set @@session.codegen_cost_threshold = '1'::money;
set application_name = '00:00:01'::time;
set @@session.application_name = '00:00:01'::time;
-- test procedure -- test procedure
create table test_pro(a int); create table test_pro(a int);

View File

@ -43,6 +43,19 @@ set codegen_cost_threshold = 10000 * 1;
ERROR: SET supported expr value only in B_FORMAT and enable_set_variable_b_format is on. ERROR: SET supported expr value only in B_FORMAT and enable_set_variable_b_format is on.
set codegen_cost_threshold = (select 10000); set codegen_cost_threshold = (select 10000);
ERROR: SET supported expr value only in B_FORMAT and enable_set_variable_b_format is on. ERROR: SET supported expr value only in B_FORMAT and enable_set_variable_b_format is on.
-- test type not support
set codegen_cost_threshold = '1'::money;
ERROR: SET supported expr value only in B_FORMAT and enable_set_variable_b_format is on.
set @@session.codegen_cost_threshold = '1'::money;
ERROR: syntax error at or near "@@"
LINE 1: set @@session.codegen_cost_threshold = '1'::money;
^
set application_name = '00:00:01'::time;
ERROR: SET supported expr value only in B_FORMAT and enable_set_variable_b_format is on.
set @@session.application_name = '00:00:01'::time;
ERROR: syntax error at or near "@@"
LINE 1: set @@session.application_name = '00:00:01'::time;
^
create database test_set dbcompatibility 'b'; create database test_set dbcompatibility 'b';
\c test_set \c test_set
-- dbcompatibility is B Format, enable_set_variable_b_format=off -- dbcompatibility is B Format, enable_set_variable_b_format=off
@ -522,6 +535,15 @@ LINE 1: set global log_destination = stderr,syslog , @v1:= 1, @@code...
set global log_destination = 'stderr', @v1:= 1, @@codegen_cost_threshold = 'aa'; set global log_destination = 'stderr', @v1:= 1, @@codegen_cost_threshold = 'aa';
NOTICE: global parameter log_destination has been set NOTICE: global parameter log_destination has been set
ERROR: invalid value for parameter "codegen_cost_threshold": "aa" ERROR: invalid value for parameter "codegen_cost_threshold": "aa"
-- test type not support
set codegen_cost_threshold = '1'::money;
ERROR: set value cannot be assigned to the money type
set @@session.codegen_cost_threshold = '1'::money;
ERROR: set value cannot be assigned to the money type
set application_name = '00:00:01'::time;
ERROR: set value cannot be assigned to the time without time zone type
set @@session.application_name = '00:00:01'::time;
ERROR: set value cannot be assigned to the time without time zone type
-- test procedure -- test procedure
create table test_pro(a int); create table test_pro(a int);
create or replace procedure pro1() create or replace procedure pro1()