Skip to content

Commit 7ae6b26

Browse files
committed
don't try to cast tracked constant when constant is of composite type - simple IO conversions doesn't work due possibly different number of attributes, dropped attributes and etc - real constant conversions is possible, but requires lot of code
1 parent 9ee2ddf commit 7ae6b26

3 files changed

Lines changed: 50 additions & 8 deletions

File tree

expected/plpgsql_check_active_4.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9693,3 +9693,23 @@ select * from plpgsql_check_function('volatility_check()');
96939693
(3 rows)
96949694

96959695
drop function volatility_check();
9696+
-- issue #201 - should not to raise false error, when composite
9697+
-- constant is used and assigned to composite with more fields
9698+
create type t_retcode as (retcode varchar, errmsg varchar, id int);
9699+
create or replace function test_retcode_bad()
9700+
returns void as $$
9701+
declare
9702+
rc t_retcode := row('MO_REG_ERROR');
9703+
begin
9704+
raise notice '%', rc.retcode;
9705+
end;
9706+
$$ language plpgsql;
9707+
select * from plpgsql_check_function('test_retcode_bad');
9708+
plpgsql_check_function
9709+
------------------------------------------------------------------------------
9710+
warning:00000:4:statement block:too few attributes for composite variable
9711+
Context: during statement block local variable "rc" initialization on line 3
9712+
(2 rows)
9713+
9714+
drop function test_retcode_bad;
9715+
drop type t_retcode;

sql/plpgsql_check_active.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5793,3 +5793,22 @@ $$ language plpgsql stable;
57935793
select * from plpgsql_check_function('volatility_check()');
57945794

57955795
drop function volatility_check();
5796+
5797+
-- issue #201 - should not to raise false error, when composite
5798+
-- constant is used and assigned to composite with more fields
5799+
create type t_retcode as (retcode varchar, errmsg varchar, id int);
5800+
5801+
create or replace function test_retcode_bad()
5802+
returns void as $$
5803+
declare
5804+
rc t_retcode := row('MO_REG_ERROR');
5805+
begin
5806+
raise notice '%', rc.retcode;
5807+
end;
5808+
$$ language plpgsql;
5809+
5810+
select * from plpgsql_check_function('test_retcode_bad');
5811+
5812+
drop function test_retcode_bad;
5813+
drop type t_retcode;
5814+

src/check_expr.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,6 @@ free_string_constant(PLpgSQL_checkstate *cstate, PLpgSQL_row *row)
13081308
}
13091309
}
13101310

1311-
13121311
/*
13131312
* Check expression as rvalue - on right in assign statement. It is used for
13141313
* only expression check too - when target is unknown.
@@ -1406,17 +1405,21 @@ plpgsql_check_expr_as_rvalue(PLpgSQL_checkstate *cstate, PLpgSQL_expr *expr,
14061405

14071406
/* When expr is constant string, try it cast to target type */
14081407
str = plpgsql_check_get_const_string(cstate, node, NULL);
1409-
14101408
if (str)
14111409
{
1412-
Oid infunc;
1413-
Oid intypeioparam;
1414-
Oid typeid;
1410+
Oid expr_typoid = exprType((Node *) node);
14151411

1416-
typeid = use_element_type ? get_array_type(expected_typoid) : expected_typoid;
1412+
if (!type_is_rowtype(expr_typoid) && !type_is_rowtype(expected_typoid))
1413+
{
1414+
Oid infunc;
1415+
Oid intypeioparam;
1416+
Oid typeid;
14171417

1418-
getTypeInputInfo(typeid, &infunc, &intypeioparam);
1419-
(void) OidInputFunctionCall(infunc, str, intypeioparam, -1);
1418+
typeid = use_element_type ? get_array_type(expected_typoid) : expected_typoid;
1419+
1420+
getTypeInputInfo(typeid, &infunc, &intypeioparam);
1421+
(void) OidInputFunctionCall(infunc, str, intypeioparam, -1);
1422+
}
14201423
}
14211424
}
14221425

0 commit comments

Comments
 (0)