修复interval类型在存储过程复制流程中赋值报错的bug

This commit is contained in:
luozihao
2023-08-28 20:00:36 +08:00
parent 4ef1c6ef71
commit a6720f2a11
3 changed files with 97 additions and 2 deletions

View File

@ -12580,7 +12580,8 @@ static Datum exec_cast_value(PLpgSQL_execstate* estate, Datum value, Oid valtype
/* get the implicit cast function from valtype to reqtype */
result = find_coercion_pathway(reqtype, valtype, COERCION_ASSIGNMENT, &funcid);
if (funcid != InvalidOid && !(result == COERCION_PATH_COERCEVIAIO || result == COERCION_PATH_ARRAYCOERCE)) {
value = OidFunctionCall1(funcid, value);
value = (reqtype == INTERVALOID) ?
OidFunctionCall2(funcid, value, reqtypmod) : OidFunctionCall1(funcid, value);
value = pl_coerce_type_typmod(value, reqtype, reqtypmod);
} else {
extval = convert_value_to_string(estate, value, valtype);

View File

@ -1310,3 +1310,58 @@ select '15'::bpchar(2)::INTERVAL YEAR;
@ 15 years
(1 row)
-- test abourt interval typmod in procedure
drop table if exists all_datatype_tbl;
NOTICE: table "all_datatype_tbl" does not exist, skipping
create table all_datatype_tbl(
c_id integer,
c_boolean boolean,
c_integer integer, c_bigint bigint,
c_real real,
c_decimal decimal(38), c_number number(38),
c_char char(50) default null, c_varchar varchar(50), c_clob clob,
c_blob blob,
c_timestamp timestamp, c_interval interval day to second) with (segment=on) ;
create or replace procedure pro_012()
as
sqlstat varchar(500);
v1 interval day to second;
begin
v1 := '12 12:3:4.1234';
sqlstat := 'insert into all_datatype_tbl(c_interval) select :p1';
execute immediate sqlstat using v1;
end;
/
call pro_012();
pro_012
---------
(1 row)
select c_interval from all_datatype_tbl;
c_interval
---------------------------------------
@ 12 days 12 hours 3 mins 4.1234 secs
(1 row)
drop procedure pro_012;
create or replace procedure pro_015()
as
sqlstat varchar(500);
v1 interval day to second;
r1 interval day to second;
begin
v1 := '12 12:3:4.1234';
sqlstat := 'select :p1';
execute immediate sqlstat into r1 using v1;
raise info 'result:%',v1;
end;
/
call pro_015();
INFO: result:@ 12 days 12 hours 3 mins 4.1234 secs
pro_015
---------
(1 row)
drop procedure pro_015;

View File

@ -367,4 +367,43 @@ select '15'::float8::INTERVAL YEAR;
select '15'::numeric::INTERVAL YEAR;
select '15'::text::INTERVAL YEAR;
select '15'::varchar::INTERVAL YEAR;
select '15'::bpchar(2)::INTERVAL YEAR;
select '15'::bpchar(2)::INTERVAL YEAR;
-- test abourt interval typmod in procedure
drop table if exists all_datatype_tbl;
create table all_datatype_tbl(
c_id integer,
c_boolean boolean,
c_integer integer, c_bigint bigint,
c_real real,
c_decimal decimal(38), c_number number(38),
c_char char(50) default null, c_varchar varchar(50), c_clob clob,
c_blob blob,
c_timestamp timestamp, c_interval interval day to second) with (segment=on) ;
create or replace procedure pro_012()
as
sqlstat varchar(500);
v1 interval day to second;
begin
v1 := '12 12:3:4.1234';
sqlstat := 'insert into all_datatype_tbl(c_interval) select :p1';
execute immediate sqlstat using v1;
end;
/
call pro_012();
select c_interval from all_datatype_tbl;
drop procedure pro_012;
create or replace procedure pro_015()
as
sqlstat varchar(500);
v1 interval day to second;
r1 interval day to second;
begin
v1 := '12 12:3:4.1234';
sqlstat := 'select :p1';
execute immediate sqlstat into r1 using v1;
raise info 'result:%',v1;
end;
/
call pro_015();
drop procedure pro_015;