!2459 修复set系统变量设置不支持类型变量转换导致的core问题
Merge pull request !2459 from suncan/master
This commit is contained in:
@ -2807,18 +2807,32 @@ Node *transferConstToAconst(Node *node)
|
||||
const char *constr = value ? "t" : "f";
|
||||
val = makeString((char*)constr);
|
||||
} break;
|
||||
case UNKNOWNOID:
|
||||
{
|
||||
Const* con = (Const *)node;
|
||||
Node* expr = coerce_type(NULL,(Node*)con , con->consttype, TEXTOID, -1, COERCION_IMPLICIT, COERCE_IMPLICIT_CAST, -1);
|
||||
char* constr = TextDatumGetCString(((Const*)expr)->constvalue);
|
||||
val = makeString(constr);
|
||||
} break;
|
||||
/*
|
||||
* 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:
|
||||
{
|
||||
char* constr = TextDatumGetCString(constval);
|
||||
val = makeString(constr);
|
||||
} break;
|
||||
PG_TRY();
|
||||
{
|
||||
Const* con = (Const *)node;
|
||||
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);
|
||||
val = makeString(constr);
|
||||
} else {
|
||||
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_FUNCTION),
|
||||
errmsg("set value cannot be assigned to the %s type", format_type_be(consttype))));
|
||||
}
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_FUNCTION),
|
||||
errmsg("set value cannot be assigned to the %s type", format_type_be(consttype))));
|
||||
}
|
||||
PG_END_TRY();
|
||||
} break;
|
||||
}
|
||||
|
||||
result = makeAConst(val, -1);
|
||||
|
@ -19,6 +19,12 @@ set session codegen_cost_threshold = 10000 * 1;
|
||||
set codegen_cost_threshold = 10000 * 1;
|
||||
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';
|
||||
\c test_set
|
||||
-- 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', @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
|
||||
create table test_pro(a int);
|
||||
|
||||
|
@ -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.
|
||||
set codegen_cost_threshold = (select 10000);
|
||||
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';
|
||||
\c test_set
|
||||
-- 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';
|
||||
NOTICE: global parameter log_destination has been set
|
||||
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
|
||||
create table test_pro(a int);
|
||||
create or replace procedure pro1()
|
||||
|
Reference in New Issue
Block a user